pub enum Locate {
File(PathBuf),
StdInOut,
}Expand description
An wrapper for representing file or stdin / stdout
Variants§
Implementations§
Source§impl Locate
impl Locate
Sourcepub fn new(locate: Option<PathBuf>) -> Self
pub fn new(locate: Option<PathBuf>) -> Self
Creates a new Locate.
- Some(x) ->
Locate::File - None ->
Locate::StdInOut(stdin / stdout)
Sourcepub fn to_path_buf(&self) -> PathBuf
pub fn to_path_buf(&self) -> PathBuf
Sourcepub fn output_path(&self, input: &Locate, id: &str, format: &Format) -> Self
pub fn output_path(&self, input: &Locate, id: &str, format: &Format) -> Self
Creates image’s output path.
input- An inputLocate.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);Sourcepub fn combined_output_path(&self, input: &Locate, id: &str) -> Option<Self>
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);Sourcepub async fn write(
&self,
stream: impl Stream<Item = Result<Bytes, Error>> + Unpin,
) -> Result<()>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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