pub struct Output<T> { /* private fields */ }
Expand description
Represents the output of an operation along with a Vec
of any
Warning
s generated by the operation.
If the contained type T
implements the Positional
trait, then
Output<T>
will also implement the Positional
trait, and will apply any
changes to both the contained output and the contained Warning
s.
Implementations§
Source§impl<T> Output<T>
impl<T> Output<T>
Sourcepub fn with_warnings(self, warnings: Vec<Warning>) -> Self
pub fn with_warnings(self, warnings: Vec<Warning>) -> Self
Builder method to add Warning
s to an Output
and return the object
§Arguments
warnings
- The list ofWarning
s to add to the object
§Examples
use tweep::{FullContext, Output, Warning, WarningKind};
let warnings = vec![ Warning::new(WarningKind::MissingStoryTitle, Some(context)) ];
let out:Output<u32> = Output::new(23).with_warnings(warnings.clone());
assert!(out.has_warnings());
assert_eq!(*out.get_warnings(), warnings);
Sourcepub fn get_output(&self) -> &T
pub fn get_output(&self) -> &T
Returns a reference to the output field
§Examples
use tweep::Output;
let out = Output::new("hail eris");
assert_eq!(*out.get_output(), "hail eris");
Sourcepub fn mut_output(&mut self) -> &mut T
pub fn mut_output(&mut self) -> &mut T
Returns a mutable reference to the output field
§Examples
use tweep::Output;
let mut out = Output::new(23 as usize);
*out.mut_output() = 5;
assert_eq!(*out.get_output(), 5);
Sourcepub fn has_warnings(&self) -> bool
pub fn has_warnings(&self) -> bool
Returns true
if the object has associated Warning
s
§Examples
use tweep::{FullContext, Output, Warning, WarningKind};
let out:Output<u8> = Output::new(5);
assert!(!out.has_warnings());
let out:Output<u8> = Output::new(5)
.with_warnings(vec![ Warning::new(WarningKind::UnclosedLink, Some(context)) ]);
assert!(out.has_warnings());
Sourcepub fn get_warnings(&self) -> &Vec<Warning>
pub fn get_warnings(&self) -> &Vec<Warning>
Returns a reference to the associated Vec
of Warning
s
§Examples
use tweep::{FullContext, Output, Warning, WarningKind};
let out:Output<u8> = Output::new(5)
.with_warnings(vec![ Warning::new(WarningKind::UnclosedLink, Some(context.clone())) ]);
assert_eq!(out.get_warnings(), &vec![ Warning::new(WarningKind::UnclosedLink, Some(context)) ]);
Sourcepub fn take(self) -> (T, Vec<Warning>)
pub fn take(self) -> (T, Vec<Warning>)
Consumes the Output
and returns the output
and warnings
as a tuple
§Examples
use tweep::{FullContext, Output, Warning, WarningKind};
let warnings = vec![ Warning::new(WarningKind::MissingStoryTitle, Some(context.clone())) ];
let out:Output<u32> = Output::new(23).with_warnings(warnings.clone());
let (t, w) = out.take();
assert_eq!(t, 23);
assert_eq!(w, warnings);
// Error!
// let _ = out.get_output();
Source§impl<T, E> Output<Result<T, E>>
This provides a handful of utility methods for an Output
that contains a
Result
as its contained output
impl<T, E> Output<Result<T, E>>
This provides a handful of utility methods for an Output
that contains a
Result
as its contained output
Sourcepub fn is_ok(&self) -> bool
pub fn is_ok(&self) -> bool
Returns true
if the contained Result
is Ok
§Examples
use tweep::{Output, Error};
let out:Output<Result<u32, Error>> = Output::new(Ok(23));
assert!(out.is_ok());
Sourcepub fn is_err(&self) -> bool
pub fn is_err(&self) -> bool
Returns true
if the contained Result
is Err
§Examples
use tweep::{Output, Error, ErrorKind, FullContext};
let context = FullContext::from(None, "::".to_string());
let err = Error::new(ErrorKind::EmptyName, Some(context));
let out:Output<Result<u32, Error>> = Output::new(Err(err));
assert!(out.is_err());
Sourcepub fn into_ok<U, F>(self) -> Output<Result<U, F>>where
T: Into<U>,
pub fn into_ok<U, F>(self) -> Output<Result<U, F>>where
T: Into<U>,
Converts this Output<Result<T,E>>
into an Output<Result<U,F>>
, where
T
can be converted into U
.
§Panics
Panics if the contained Result<T,E>
is not Ok
§Examples
use tweep::{Output, Error};
let out:Output<Result<u8, Error>> = Output::new(Ok(23));
// The destination Error type does not need to be convertible from the source
let other:Output<Result<u32, String>> = out.into_ok();
assert!(other.is_ok());
assert_eq!(*other.get_output(), Ok(23));
Sourcepub fn into_err<U, F>(self) -> Output<Result<U, F>>where
E: Into<F>,
pub fn into_err<U, F>(self) -> Output<Result<U, F>>where
E: Into<F>,
Converts this Output<Result<T,E>>
into an Output<Result<U,F>>
, where
E
can be converted into F
§Panics
Panics if the contained Result<T,E>
is not Err
§Examples
use tweep::Output;
let out:Output<Result<u8, u8>> = Output::new(Err(5));
// The destination Ok type does not need to be convertible from the source
let other:Output<Result<String, u32>> = out.into_err();
assert!(other.is_err());
assert_eq!(*other.get_output(), Err(5));
Sourcepub fn into_result<U, F>(self) -> Output<Result<U, F>>
pub fn into_result<U, F>(self) -> Output<Result<U, F>>
Converts this Output<Result<T,E>>
into an Output<Result<U,F>>
, where
T
can be converted into U
and E
can be converted into F
§Examples
use tweep::Output;
let mut out:Output<Result<u8, u8>> = Output::new(Ok(23));
let mut other:Output<Result<u32, u32>> = out.into_result();
assert!(other.is_ok());
assert_eq!(*other.get_output(), Ok(23));
out = Output::new(Err(5));
other = out.into_result();
assert!(other.is_err());
assert_eq!(*other.get_output(), Err(5));