Skip to content

Commit

Permalink
feature: Implement TryFrom (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfreyer committed May 26, 2019
1 parent 6ed36aa commit 2d812cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added

* implementations for `TryFrom` to start / stop jails.
* example showing how to query RCTL usage.
* code coverage with codecov.io. Unfortunately, this doesn't yet take docstests
into account, so coverage is actually a bit better in reality.
Expand Down
9 changes: 9 additions & 0 deletions src/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use JailError;
use StoppedJail;

use std::collections::HashMap;
use std::convert::TryFrom;
use std::io::{Error, ErrorKind};
use std::net;
use std::path;
Expand Down Expand Up @@ -545,6 +546,14 @@ impl RunningJail {
}
}

impl TryFrom<StoppedJail> for RunningJail {
type Error = JailError;

fn try_from(stopped: StoppedJail) -> Result<RunningJail, Self::Error> {
stopped.start()
}
}

/// An Iterator over running Jails
///
/// See [RunningJail::all()](struct.RunningJail.html#method.all) for a usage
Expand Down
9 changes: 9 additions & 0 deletions src/stopped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use RunningJail;
#[cfg(feature = "serialize")]
use serde::Serialize;

use std::convert::TryFrom;
use std::fmt;

/// Represent a stopped jail including all information required to start it
Expand Down Expand Up @@ -52,6 +53,14 @@ impl Default for StoppedJail {
}
}

impl TryFrom<RunningJail> for StoppedJail {
type Error = JailError;

fn try_from(running: RunningJail) -> Result<StoppedJail, Self::Error> {
running.stop()
}
}

#[cfg(target_os = "freebsd")]
impl StoppedJail {
/// Create a new Jail instance given a path.
Expand Down

0 comments on commit 2d812cf

Please sign in to comment.