[−][src]Struct tweep::Output
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.
Methods
impl<T> Output<T>
[src]
pub fn new(value: T) -> Self
[src]
Creates a new Output
with the given value and no Warning
s
Arguments
value
- The output value
Examples
use tweep::Output; let out:Output<u32> = Output::new(23); assert_eq!(*out.get_output(), 23); assert!(!out.has_warnings());
pub fn with_warnings(self, warnings: Vec<Warning>) -> Self
[src]
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::{Output, Warning, WarningType}; let warnings = vec![ Warning::new(WarningType::MissingStoryTitle) ]; let out:Output<u32> = Output::new(23).with_warnings(warnings.clone()); assert!(out.has_warnings()); assert_eq!(*out.get_warnings(), warnings);
pub fn get_output(&self) -> &T
[src]
Returns a reference to the output field
Examples
use tweep::Output; let out = Output::new("hail eris"); assert_eq!(*out.get_output(), "hail eris");
pub fn has_warnings(&self) -> bool
[src]
Returns true
if the object has associated Warning
s
Examples
use tweep::{Output, Warning, WarningType}; let out:Output<u8> = Output::new(5); assert!(!out.has_warnings()); let out:Output<u8> = Output::new(5) .with_warnings(vec![ Warning::new(WarningType::UnclosedLink) ]); assert!(out.has_warnings());
pub fn get_warnings(&self) -> &Vec<Warning>
[src]
Returns a reference to the associated Vec
of Warning
s
Examples
use tweep::{Output, Warning, WarningType}; let out:Output<u8> = Output::new(5) .with_warnings(vec![ Warning::new(WarningType::UnclosedLink) ]); assert_eq!(out.get_warnings(), &vec![ Warning::new(WarningType::UnclosedLink) ]);
pub fn take(self) -> (T, Vec<Warning>)
[src]
Consumes the Output
and returns the output
and warnings
as a tuple
Examples
use tweep::{Output, Warning, WarningType}; let warnings = vec![ Warning::new(WarningType::MissingStoryTitle) ]; 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();
impl<T, E> Output<Result<T, E>>
[src]
This provides a handful of utility methods for an Output
that contains a
Result
as its contained output
pub fn is_ok(&self) -> bool
[src]
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());
pub fn is_err(&self) -> bool
[src]
Returns true
if the contained Result
is Err
Examples
use tweep::{Output, Error, ErrorType}; let out:Output<Result<u32, Error>> = Output::new(Err(Error::new(ErrorType::EmptyName))); assert!(out.is_err());
pub fn into_ok<U, F>(self) -> Output<Result<U, F>> where
T: Into<U>,
[src]
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));
pub fn into_err<U, F>(self) -> Output<Result<U, F>> where
E: Into<F>,
[src]
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));
pub fn into_result<U, F>(self) -> Output<Result<U, F>> where
T: Into<U>,
E: Into<F>,
[src]
T: Into<U>,
E: Into<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));
Trait Implementations
impl<T> Positional for Output<T> where
T: Positional,
[src]
T: Positional,
fn set_row(&mut self, row: usize)
[src]
fn set_column(&mut self, col: usize)
[src]
fn offset_column(&mut self, offset: usize)
[src]
fn offset_row(&mut self, offset: usize)
[src]
fn set_file(&mut self, file: String)
[src]
fn get_position(&self) -> &Position
[src]
fn mut_position(&mut self) -> &mut Position
[src]
fn get_column(&self) -> Option<usize>
[src]
fn get_row(&self) -> Option<usize>
[src]
fn get_file(&self) -> Option<&str>
[src]
fn with_offset_row(self, offset: usize) -> Self where
Self: Sized,
[src]
Self: Sized,
fn with_offset_column(self, offset: usize) -> Self where
Self: Sized,
[src]
Self: Sized,
fn with_column(self, col: usize) -> Self where
Self: Sized,
[src]
Self: Sized,
fn with_row(self, row: usize) -> Self where
Self: Sized,
[src]
Self: Sized,
fn with_file(self, file: String) -> Self where
Self: Sized,
[src]
Self: Sized,
Auto Trait Implementations
impl<T> RefUnwindSafe for Output<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Output<T> where
T: Send,
T: Send,
impl<T> Sync for Output<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Output<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Output<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,