Locate

Enum Locate 

Source
pub enum Locate {
    File(PathBuf),
    StdInOut,
}
Expand description

An wrapper for representing file or stdin / stdout

Variants§

§

File(PathBuf)

§

StdInOut

Implementations§

Source§

impl Locate

Source

pub fn new(locate: Option<PathBuf>) -> Self

Creates a new Locate.

Source

pub fn to_path_buf(&self) -> PathBuf

Converts a Locate to an owned PathBuf.

Source

pub fn output_path(&self, input: &Locate, id: &str, format: &Format) -> Self

Creates image’s output path.

  • input - An input Locate.
  • id - Identifiers in the PlantUML diagram.
  • format - A format of output.
§Examples
let locate = Locate::from("./output/dir");
let output_path = locate.output_path(&"./foo.puml".into(), "id_a", &Format::Svg);

let expected = Locate::from(PathBuf::from("./output/dir/foo/id_a.svg"));
assert_eq!(output_path, expected);
let locate = Locate::from(None); // `--output` is not specified
let output_path = locate.output_path(&"./foo.puml".into(), "id_a", &Format::Svg);

let expected = Locate::from(PathBuf::from("foo/id_a.svg"));
assert_eq!(output_path, expected);
let locate = Locate::from("./output/dir");
let input = Locate::from(None); // `--input` is not specified (read from stdin)
let output_path = locate.output_path(&input, "id_a", &Format::Svg);

let expected = Locate::from(PathBuf::from("./output/dir/id_a.svg"));
assert_eq!(output_path, expected);
let locate = Locate::from(None);
let input = Locate::from(None);
let output_path = locate.output_path(&input, "N/A", &Format::Svg);

let expected = Locate::from(None);
assert_eq!(output_path, expected);
Source

pub fn combined_output_path(&self, input: &Locate, id: &str) -> Option<Self>

Creates “combined” PlantUML content’s path. The “combined PlantUML content” is output when the --combined option is specified.

§Examples
let locate = Locate::from("./output/dir");
let output_path = locate.combined_output_path(&"./foo.puml".into(), "id_a");

let expected_path = "./output/dir/foo/id_a.puml"; // different extension from `output_path()`.
let expected = Some(Locate::from(PathBuf::from(expected_path)));
assert_eq!(output_path, expected);
Source

pub fn read(&self) -> Result<String>

Read from the Locate.

§Examples
let locate = Locate::from("./target/tests_docs/locate_read");
let data = "foo";

std::fs::write(locate.to_path_buf(), data)?;
let read_data = locate.read()?;
assert_eq!(read_data, data);
Source

pub async fn write( &self, stream: impl Stream<Item = Result<Bytes, Error>> + Unpin, ) -> Result<()>

Write a stream to Locate.

  • stream - Data to write
§Examples
let locate = Locate::from("./target/tests_docs/locate_write");
let data = "foo2";
let stream = futures::stream::iter(vec![Ok(data.into())]);

locate.write(stream).await?;
let read_data = std::fs::read_to_string(locate.to_path_buf())?;
assert_eq!(read_data, data);

Trait Implementations§

Source§

impl Debug for Locate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for Locate

Source§

fn from(inner: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Option<PathBuf>> for Locate

Source§

fn from(inner: Option<PathBuf>) -> Self

Converts to this type from the input type.
Source§

impl From<PathBuf> for Locate

Source§

fn from(inner: PathBuf) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Locate

Source§

fn eq(&self, rhs: &Locate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl Freeze for Locate

§

impl RefUnwindSafe for Locate

§

impl Send for Locate

§

impl Sync for Locate

§

impl Unpin for Locate

§

impl UnwindSafe for Locate

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,