Skip to content

Commit

Permalink
to string conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
krojew committed Oct 8, 2020
1 parent d51809e commit d2f6fa0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [x.x.x]

### New

- To string conversion from some enums

## [2.1.0]

### New
Expand Down
32 changes: 31 additions & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ pub enum ZkError {
Unimplemented = -6,
}

impl From<ZkError> for String {
fn from(value: ZkError) -> Self {
value.to_string()
}
}

/// CreateMode value determines how the znode is created on ZooKeeper.
#[derive(Clone, Copy, Debug, PartialEq, Ord, PartialOrd, Eq, Hash, Display)]
pub enum CreateMode {
Expand All @@ -84,6 +90,12 @@ pub enum CreateMode {
Container = 4,
}

impl From<CreateMode> for String {
fn from(value: CreateMode) -> Self {
value.to_string()
}
}

/// Enumeration of states the client may be at a Watcher Event. It represents the state of the
/// server at the time the event was generated.
#[derive(Clone, Copy, Debug, Display, PartialEq, Ord, PartialOrd, Eq, Hash, TryFromPrimitive)]
Expand All @@ -110,6 +122,12 @@ pub enum KeeperState {
Expired = -112,
}

impl From<KeeperState> for String {
fn from(value: KeeperState) -> Self {
value.to_string()
}
}

/// Enumeration of types of events that may occur on the znode.
#[derive(Clone, Copy, Debug, Display, Ord, PartialOrd, Eq, PartialEq, Hash, TryFromPrimitive)]
#[repr(i32)]
Expand All @@ -134,8 +152,14 @@ pub enum WatchedEventType {
ChildWatchRemoved = 6,
}

impl From<WatchedEventType> for String {
fn from(value: WatchedEventType) -> Self {
value.to_string()
}
}

/// Enumeration of states the client may be at any time.
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Display)]
pub enum ZkState {
/// Previously used to represent a state between connection (as in connected to a server) and
/// authenticated. This is no longer used.
Expand All @@ -158,3 +182,9 @@ pub enum ZkState {
#[deprecated]
NotConnected,
}

impl From<ZkState> for String {
fn from(value: ZkState) -> Self {
value.to_string()
}
}

0 comments on commit d2f6fa0

Please sign in to comment.