pub struct Linear<T>(/* private fields */);Expand description
A linear type that must be destructured to access the inner value.
Implementations§
Source§impl<T> Linear<T>
impl<T> Linear<T>
Sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Returns a reference to the inner value.
In a pure linear type-system even immutable access to the inner value is not available
because this may leak unwanted interior mutability or enable to clone the inner which
would be impure (in a linear type system). When one doesn’t do either then the rust
type system/lifetimes are strong enough to be pure. This method is only available when
one defines the semipure feature. It’s then the decision of the programmer not to use
any interior mutability/cloning or bend the rules and do something impure to make this
crate more convenient to use.
§Example
let linear = Linear::new(123);
assert_eq!(linear.get_ref(), &123);Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Destructures the linear type and returns the inner type. This must eventually be called on any linear type, failing to do so will panic.
§Example
let linear = Linear::new(123);
let inner = linear.into_inner();
assert_eq!(inner, 123);Sourcepub fn map<F: FnOnce(T) -> R, R>(self, f: F) -> Linear<R>
pub fn map<F: FnOnce(T) -> R, R>(self, f: F) -> Linear<R>
Transforms one linear type to another linear type. The inner value is passed to the
closure and the return value is wrapped in a Linear.
§Example
let number = Linear::new(123);
let string = number.map(|x| x.to_string());
assert_eq!(string.into_inner(), "123");Source§impl<T: Debug, E: Debug> Linear<Result<T, E>>
Additional methods for Linear<Result<R,E>>, only fundamental map and unwrap methods are
supported. Anything beyond that needs to be handled manually.
impl<T: Debug, E: Debug> Linear<Result<T, E>>
Additional methods for Linear<Result<R,E>>, only fundamental map and unwrap methods are
supported. Anything beyond that needs to be handled manually.
Sourcepub fn map_ok<F: FnOnce(T) -> Result<R, E>, R>(
self,
f: F,
) -> Linear<Result<R, E>>
pub fn map_ok<F: FnOnce(T) -> Result<R, E>, R>( self, f: F, ) -> Linear<Result<R, E>>
Transforms a Linear<Result<T,E>> into Linear<Result<R,E>> by applying a function
to the Ok value. Retains a Err value.
Sourcepub fn map_err<F: FnOnce(E) -> Result<T, R>, R>(
self,
f: F,
) -> Linear<Result<T, R>>
pub fn map_err<F: FnOnce(E) -> Result<T, R>, R>( self, f: F, ) -> Linear<Result<T, R>>
Transforms a Linear<Result<T,E>> into Linear<Result<T, R>> by applying a function
to the Err value. Retains a Ok value.
Sourcepub fn unwrap_err(self) -> Linear<E>
pub fn unwrap_err(self) -> Linear<E>
Source§impl<T> Linear<Option<T>>
Additional methods for Linear<Option<T>>, only fundamental methods are supported.
Anything beyond that needs to be handled manually.
impl<T> Linear<Option<T>>
Additional methods for Linear<Option<T>>, only fundamental methods are supported.
Anything beyond that needs to be handled manually.
Sourcepub fn map_some<F: FnOnce(T) -> Option<R>, R>(self, f: F) -> Linear<Option<R>>
pub fn map_some<F: FnOnce(T) -> Option<R>, R>(self, f: F) -> Linear<Option<R>>
Transforms a Linear<Option<T>> into Linear<Option<R>> by applying a function
to the Some value. Retains a None value.
Sourcepub fn or_else<F: FnOnce() -> Option<T>>(self, f: F) -> Self
pub fn or_else<F: FnOnce() -> Option<T>>(self, f: F) -> Self
Transforms a Linear<Option<T>> into Linear<Option<T>> by applying a function
to the None value. Retains a Some value.