Almost

Enum Almost 

Source
pub enum Almost<T> {
    Nil,
    Value(T),
}
Expand description

A type similar to Option but with Deref<Target = T> implementation. See crate-level documentation for more info.

Variants§

§

Nil

§

Value(T)

Implementations§

Source§

impl<T> Almost<T>

Source

pub const fn is_value(this: &Self) -> bool

Returns true if the almost is a Value value.

§Examples
let x: Almost<u32> = Value(2);
assert!(Almost::is_value(&x));

let x: Almost<u32> = Nil;
assert!(Almost::is_nil(&x));
Source

pub fn is_value_and(this: Self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the almost is a Value and the value inside of it matches a predicate.

§Examples
let x: Almost<u32> = Value(2);
assert!(Almost::is_value_and(x, |x| x > 1));

let x: Almost<u32> = Value(0);
assert!(!Almost::is_value_and(x, |x| x > 1));

let x: Almost<u32> = Nil;
assert!(!Almost::is_value_and(x, |x| x > 1));

let x: Almost<String> = Value("ownership".to_string());
assert!(Almost::is_value_and(Almost::as_ref(&x), |x| x.len() > 1));
println!("still alive {:?}", x);
Source

pub const fn is_nil(this: &Self) -> bool

Returns true if the almost is a Value value.

§Examples
let x: Almost<u32> = Value(2);
assert!(!Almost::is_nil(&x));

let x: Almost<u32> = Nil;
assert!(Almost::is_nil(&x));
Source

pub fn is_nil_or(this: Self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the almost is a Value or the value inside of it matches a predicate.

§Examples
let x: Almost<u32> = Value(2);
assert!(Almost::is_nil_or(x, |x| x > 1));

let x: Almost<u32> = Value(0);
assert!(!Almost::is_nil_or(x, |x| x > 1));

let x: Almost<u32> = Nil;
assert!(Almost::is_nil_or(x, |x| x > 1));

let x: Almost<String> = Value("ownership".to_string());
assert!(Almost::is_nil_or(Almost::as_ref(&x), |x| x.len() > 1));
println!("still alive {:?}", x);
Source

pub const fn as_ref(this: &Self) -> Almost<&T>

Converts from &Almost<T> to Almost<&T>

Source

pub const fn as_mut(this: &mut Self) -> Almost<&mut T>

Converts from &mut Almost<T> to Almost<&mut T>

§Examples
let mut x = Value(2);
match Almost::as_mut(&mut x) {
    Value(v) => *v = 42,
    Nil => {},
}
assert_eq!(x, Value(42));
Source

pub const fn as_pin_ref(this: Pin<&Self>) -> Almost<Pin<&T>>

Converts from Pin<&Almost<T>> to Almost<Pin<&T>>

Source

pub const fn as_pin_mut(this: Pin<&mut Self>) -> Almost<Pin<&mut T>>

Converts from Pin<&mut Almost<T>> to Almost<Pin<&mut T>>

Source

pub const fn as_slice(this: &Self) -> &[T]

Returns a slice of the contained value, if any. If this is Nil, an empty slice is returned. This can be useful to have a single type of iterator over an Almost or slice.

Note: Should you have an Almost<&T> and wish to get a slice of T, you can unpack it via Almost::map_or(opt, &[], std::slice::from_ref).

§Examples
assert_eq!(Almost::as_slice(&Value(1234)), &[1234][..]);
assert_eq!(Almost::as_slice(&Nil::<i32>), &[][..]);
Source

pub const fn as_slice_mut(this: &mut Self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is Nil, an empty slice is returned. This can be useful to have a single type of iterator over an Almost or slice.

§Examples
assert_eq!(Almost::as_slice_mut(&mut Value(1234)), &mut [1234][..]);
assert_eq!(Almost::as_slice_mut(&mut Nil::<i32>), &mut [][..]);
Source

pub fn expect(this: Self, msg: &str) -> T

Returns the contained Value value, consuming the self value.

§Panics

Panics if the value is a Nil with a custom panic message provided by msg.

§Examples
let x = Value("value");
assert_eq!(Almost::expect(x, "fruits are healthy"), "value");
let x: Almost<&str> = Nil;
Almost::expect(x, "fruits are healthy"); // panics with `fruits are healthy`

We recommend that expect messages are used to describe the reason you expect the Almost should be Value.

let maybe_item = Almost::from_option(slice.get(0));
let item = Almost::expect(maybe_item, "slice should not be empty");
Source

pub fn unwrap(this: Self) -> T

Returns the contained Value value, consuming the self value.

Because this function may panic, its use is generally discouraged. Panics are meant for unrecoverable errors, and may abort the entire program.

Instead, prefer to use pattern matching and handle the Nil case explicitly, or call Almost::unwrap_or, Almost::unwrap_or_else, or Almost::unwrap_or_default.

§Panics

Panics if the self value equals Nil.

§Examples
let x = Value("air");
assert_eq!(Almost::unwrap(x), "air");
let x: Almost<&str> = Nil;
assert_eq!(Almost::unwrap(x), "air"); // fails
Source

pub fn unwrap_or(this: Self, default: T) -> T

Returns the contained Value value or a provided default.

Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Almost::unwrap_or_else, which is lazily evaluated.

§Examples
assert_eq!(Almost::unwrap_or(Value("car"), "bike"), "car");
assert_eq!(Almost::unwrap_or(Nil, "bike"), "bike");
Source

pub fn unwrap_or_else(this: Self, f: impl FnOnce() -> T) -> T

Returns the contained Value value or computes it from a closure.

§Examples
let k = 10;
assert_eq!(Almost::unwrap_or_else(Value(4), || 2 * k), 4);
assert_eq!(Almost::unwrap_or_else(Nil, || 2 * k), 20);
Source

pub fn unwrap_or_default(this: Self) -> T
where T: Default,

Returns the contained Value value or a default.

Consumes the self argument then, if Value, returns the contained value, otherwise if Nil, returns the default value for that type.

§Examples
let x: Almost<u32> = Nil;
let y: Almost<u32> = Value(12);

assert_eq!(Almost::unwrap_or_default(x), 0);
assert_eq!(Almost::unwrap_or_default(y), 12);
Source

pub unsafe fn unwrap_unchecked(this: Self) -> T

Returns the contained Value value, consuming the self value, without checking that the value is not Value.

§Safety

Calling this method on Nil is undefined behavior.

§Examples
let x = Value("air");
assert_eq!(unsafe { Almost::unwrap_unchecked(x) }, "air");
let x: Almost<&str> = Nil;
assert_eq!(unsafe { Almost::unwrap_unchecked(x) }, "air"); // Undefined behavior!
Source

pub fn map<U>(this: Self, f: impl FnOnce(T) -> U) -> Almost<U>

Maps an Almost<T> to Almost<U> by applying a function to a contained value (if Value) or returns Nil (if Nil).

§Examples

Calculates the length of an Almost<String> as an Almost<usize> consuming the original:

let maybe_some_string = Value(String::from("Hello, World!"));
// `Almost::map` takes self *by value*, consuming `maybe_some_string`
let maybe_some_len = Almost::map(maybe_some_string, |s| s.len());
assert_eq!(maybe_some_len, Value(13));

let x: Almost<&str> = Nil;
assert_eq!(Almost::map(x, |s| s.len()), Nil);
Source

pub fn inspect(this: Self, f: impl FnOnce(&T)) -> Self

Calls a function with a reference to the contained value if Value.

Returns the original almost.

Source

pub fn map_or<U>(this: Self, default: U, f: impl FnOnce(T) -> U) -> U

Returns the provided default result (if nil), or applies a function to the contained value (if any).

Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use Almost::map_or_else, which is lazily evaluated.

§Examples
let x = Value("foo");
assert_eq!(Almost::map_or(x, 42, |v| v.len()), 3);

let x: Almost<&str> = Nil;
assert_eq!(Almost::map_or(x, 42, |v| v.len()), 42);
Source

pub fn map_or_else<U>( this: Self, default: impl FnOnce() -> U, f: impl FnOnce(T) -> U, ) -> U

Computes a default function result (if nill), or applies a different function to the contained value (if any).

§Examples
let k = 21;

let x = Value("foo");
assert_eq!(Almost::map_or_else(x, || 2 * k, |v| v.len()), 3);

let x: Almost<&str> = Nil;
assert_eq!(Almost::map_or_else(x, || 2 * k, |v| v.len()), 42);
Source

pub fn ok_or<E>(this: Self, error: E) -> Result<T, E>

Transforms the Almost<T> into a Result<T, E>, mapping Value(v) to Ok(v) and Nil to Err(err).

Arguments passed to ok_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use ok_or_else, which is lazily evaluated.

§Examples
let x = Value("foo");
assert_eq!(Almost::ok_or(x, 0), Ok("foo"));

let x: Almost<&str> = Nil;
assert_eq!(Almost::ok_or(x, 0), Err(0));
Source

pub fn ok_or_else<E>(this: Self, error: impl FnOnce() -> E) -> Result<T, E>

Transforms the Almost<T> into a Result<T, E>, mapping Value(v) to Ok(v) and Nil to Err(err()).

§Examples
let x = Value("foo");
assert_eq!(Almost::ok_or_else(x, || 0), Ok("foo"));

let x: Almost<&str> = Nil;
assert_eq!(Almost::ok_or_else(x, || 0), Err(0));
Source

pub fn as_deref(this: &Self) -> Almost<&<T as Deref>::Target>
where T: Deref,

Converts from Almost<T> (or &Almost<T>) to Almost<&T::Target>.

Leaves the original Almost in-place, creating a new one with a reference to the original one, additionally coercing the contents via Deref.

§Examples
let x: Almost<String> = Value("hey".to_owned());
assert_eq!(Almost::as_deref(&x), Value("hey"));

let x: Almost<String> = Nil;
assert_eq!(Almost::as_deref(&x), Nil);
Source

pub fn as_deref_mut(this: &mut Self) -> Almost<&mut <T as Deref>::Target>
where T: DerefMut,

Converts from Almost<T> (or &mut Almost<T>) to Almost<&mut T::Target>.

Leaves the original Almost in-place, creating a new one containing a mutable reference to the inner type’s Deref::Target type.

§Examples
let mut x: Almost<String> = Nil;
assert_eq!(Almost::as_deref_mut(&mut x), Nil);
Source

pub fn into_option(this: Self) -> Option<T>

Converts Almost<T> into an Option<T>

§Examples
let x: Almost<i32> = Value(42);
let x: Option<i32> = Almost::into_option(x);
assert_eq!(x, Some(42));

let y = Nil::<i32>;
let y: Option<i32> = Almost::into_option(y);
assert_eq!(y, None);
Source

pub fn iter(this: &Self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

§Examples
let x = Value(4);
assert_eq!(Almost::iter(&x).next(), Some(&4));

let x: Almost<u32> = Nil;
assert_eq!(Almost::iter(&x).next(), None);
Source

pub fn iter_mut(this: &mut Self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

§Examples
let mut x = Value(4);
match Almost::iter_mut(&mut x).next() {
    Some(v) => *v = 42,
    None => {},
}
assert_eq!(x, Value(42));

let mut x: Almost<u32> = Nil;
assert_eq!(Almost::iter_mut(&mut x).next(), None);
Source

pub fn and<U>(this: Self, other: Almost<U>) -> Almost<U>

Returns Nil if the option is Nil, otherwise returns other.

Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use and_then, which is lazily evaluated.

§Examples
let x = Value(2);
let y: Almost<&str> = Nil;
assert_eq!(Almost::and(x, y), Nil);

let x: Almost<u32> = Nil;
let y = Value("foo");
assert_eq!(Almost::and(x, y), Nil);

let x = Value(2);
let y = Value("foo");
assert_eq!(Almost::and(x, y), Value("foo"));

let x: Almost<u32> = Nil;
let y: Almost<&str> = Nil;
assert_eq!(Almost::and(x, y), Nil);
Source

pub fn and_then<U>(this: Self, other: impl FnOnce(T) -> Almost<U>) -> Almost<U>

Returns Nil if the option is Nil, otherwise calls f with the wrapped value and returns the result.

Some languages call this operation flatmap.

§Examples
fn sq_then_to_string(x: u32) -> Almost<String> {
    x.checked_mul(x).map(|sq| sq.to_string()).into()
}

assert_eq!(Almost::and_then(Value(2), sq_then_to_string), Value(4.to_string()));
assert_eq!(Almost::and_then(Value(1_000_000), sq_then_to_string), Nil); // overflowed!
assert_eq!(Almost::and_then(Nil, sq_then_to_string), Nil);
Source

pub fn filter(this: Self, do_get: impl FnOnce(&T) -> bool) -> Self

Returns Nil if the option is Nil, otherwise calls predicate with the wrapped value and returns:

  • Value(t) if predicate returns true (where t is the wrapped value), and
  • Nil if predicate returns false.

This function works similar to Iterator::filter(). You can imagine the Almost<T> being an iterator over one or zero elements. filter() lets you decide which elements to keep.

§Examples
fn is_even(n: &i32) -> bool {
    n % 2 == 0
}

assert_eq!(Almost::filter(Nil, is_even), Nil);
assert_eq!(Almost::filter(Value(3), is_even), Nil);
assert_eq!(Almost::filter(Value(4), is_even), Value(4));
Source

pub fn or(this: Self, other: Self) -> Self

Returns the almost if it contains a value, otherwise returns other.

Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.

§Examples
let x = Value(2);
let y = Nil;
assert_eq!(Almost::or(x, y), Value(2));

let x = Nil;
let y = Value(100);
assert_eq!(Almost::or(x, y), Value(100));

let x = Value(2);
let y = Value(100);
assert_eq!(Almost::or(x, y), Value(2));

let x: Almost<u32> = Nil;
let y = Nil;
assert_eq!(Almost::or(x, y), Nil);
Source

pub fn or_else(this: Self, f: impl FnOnce() -> Self) -> Self

Returns the almost if it contains a value, otherwise calls f and returns the result.

§Examples
fn nobody() -> Almost<&'static str> { Nil }
fn vikings() -> Almost<&'static str> { Value("vikings") }

assert_eq!(Almost::or_else(Value("barbarians"), vikings), Value("barbarians"));
assert_eq!(Almost::or_else(Nil, vikings), Value("vikings"));
assert_eq!(Almost::or_else(Nil, nobody), Nil);
Source

pub fn xor(this: Self, other: Self) -> Self

Returns Value if exactly one of self, other is Value, otherwise returns Nil.

§Examples
let x = Value(2);
let y: Almost<u32> = Nil;
assert_eq!(Almost::xor(x, y), Value(2));

let x: Almost<u32> = Nil;
let y = Value(2);
assert_eq!(Almost::xor(x, y), Value(2));

let x = Value(2);
let y = Value(2);
assert_eq!(Almost::xor(x, y), Nil);

let x: Almost<u32> = Nil;
let y: Almost<u32> = Nil;
assert_eq!(Almost::xor(x, y), Nil);
Source

pub fn insert(this: &mut Self, value: T) -> &mut T

Inserts value into the almost, then returns a mutable reference to it.

If the almost already contains a value, the old value is dropped.

See also Almost::get_or_insert, which doesn’t update the value if the option already contains Value.

§Example
let mut almost = Nil;
let val = Almost::insert(&mut almost, 1);
assert_eq!(*val, 1);
assert_eq!(Almost::unwrap(almost), 1);

let val = Almost::insert(&mut almost, 2);
assert_eq!(*val, 2);
*val = 3;
assert_eq!(Almost::unwrap(almost), 3);
Source

pub fn get_or_insert(this: &mut Self, value: T) -> &mut T

Inserts value into the almost if it is Nil, then returns a mutable reference to the contained value.

See also Almost::insert, which updates the value even if the option already contains Almost.

§Examples
let mut x = Nil;

{
    let y: &mut u32 = Almost::get_or_insert(&mut x, 5);
    assert_eq!(y, &5);

    *y = 7;
}

assert_eq!(x, Value(7));
Source

pub fn get_or_insert_default(this: &mut Self) -> &mut T
where T: Default,

Inserts the default value into the almost if it is Nil, then returns a mutable reference to the contained value.

§Examples
let mut x = Nil;

{
    let y: &mut u32 = Almost::get_or_insert_default(&mut x);
    assert_eq!(y, &0);

    *y = 7;
}

assert_eq!(x, Value(7));
Source

pub fn get_or_insert_with(this: &mut Self, f: impl FnOnce() -> T) -> &mut T

Inserts a value computed from f into the almost if it is Nil, then returns a mutable reference to the contained value.

§Examples
let mut x = Nil;

{
    let y: &mut u32 = Almost::get_or_insert_with(&mut x, || 5);
    assert_eq!(y, &5);

    *y = 7;
}

assert_eq!(x, Value(7));
Source

pub const fn take(this: &mut Self) -> Self

Takes the value out of the almost, leaving a Nil in its place.

§Examples
let mut x = Value(2);
let y = Almost::take(&mut x);
assert_eq!(x, Nil);
assert_eq!(y, Value(2));

let mut x: Almost<u32> = Nil;
let y = Almost::take(&mut x);
assert_eq!(x, Nil);
assert_eq!(y, Nil);
Source

pub fn take_unwrap(this: &mut Self) -> T

Takes the value out of the almost, leaving a Nil in its place, then unwraps the underlying value.

§Panic

Panics if this was Nil.

§Examples
let mut x = Value(2);
let y = Almost::take_unwrap(&mut x);
assert_eq!(x, Nil);
assert_eq!(y, 2);

This panics:

let mut x: Almost<u32> = Nil;
let y = Almost::take_unwrap(&mut x);
Source

pub fn take_expect(this: &mut Self, message: &str) -> T

Takes the value out of the almost, leaving a Nil in its place, then unwraps the underlying value.

§Panic

Panics with message if this was Nil.

§Examples
let mut x = Value(2);
let y = Almost::take_expect(&mut x, "x cannot be Nil");
assert_eq!(x, Nil);
assert_eq!(y, 2);

This panics:

let mut x: Almost<u32> = Nil;
let y = Almost::take_expect(&mut x, "oops");
Source

pub fn take_if(this: &mut Self, f: impl FnOnce(&mut T) -> bool) -> Self

Takes the value out of the almost, but only if the predicate evaluates to true on a mutable reference to the value.

In other words, replaces self with Nil if the predicate returns true. This method operates similar to Almost::take but conditional.

§Examples
let mut x = Value(42);

let prev = Almost::take_if(&mut x, |v| if *v == 42 {
    *v += 1;
    false
} else {
    false
});
assert_eq!(x, Value(43));
assert_eq!(prev, Nil);

let prev = Almost::take_if(&mut x, |v| *v == 43);
assert_eq!(x, Nil);
assert_eq!(prev, Value(43));
Source

pub const fn replace(this: &mut Self, value: T) -> Self

Replaces the actual value in the almost by the value given in parameter, returning the old value if present, leaving a Value in its place without deinitializing either one.

§Examples
let mut x = Value(2);
let old = Almost::replace(&mut x, 5);
assert_eq!(x, Value(5));
assert_eq!(old, Value(2));

let mut x = Nil;
let old = Almost::replace(&mut x, 3);
assert_eq!(x, Value(3));
assert_eq!(old, Nil);
Source

pub fn zip<U>(this: Self, other: Almost<U>) -> Almost<(T, U)>

Zips self with another Almost.

If self is Value(s) and other is Value(o), this method returns Value((s, o)). Otherwise, Nil is returned.

§Examples
let x = Value(1);
let y = Value("hi");
let z = Nil::<u8>;

assert_eq!(Almost::zip(x, y), Value((1, "hi")));
assert_eq!(Almost::zip(x, z), Nil);
Source

pub fn zip_with<U, R>( this: Self, other: Almost<U>, f: impl FnOnce(T, U) -> R, ) -> Almost<R>

Zips self and another Almost with function f.

If self is Value(s) and other is Value(o), this method returns Value(f(s, o)). Otherwise, Nil is returned.

§Examples
#[derive(Debug, PartialEq)]
struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn new(x: f64, y: f64) -> Self {
        Self { x, y }
    }
}

let x = Value(17.5);
let y = Value(42.7);

assert_eq!(Almost::zip_with(x, y, Point::new), Value(Point { x: 17.5, y: 42.7 }));
assert_eq!(Almost::zip_with(x, Nil, Point::new), Nil);
Source

pub const fn get_ref(this: &Self) -> &T

Return a reference the underlying value.

§Panic

Panics if this is Nil

Source

pub const fn get_mut(this: &mut Self) -> &mut T

Return a mutable reference the underlying value.

§Panic

Panics if this is Nil

Source

pub fn from_option(value: Option<T>) -> Self

Construct Almost<T> from Option<T>.

Source§

impl<T, U> Almost<(T, U)>

Source

pub fn unzip(this: Self) -> (Almost<T>, Almost<U>)

Unzips an almost containing a tuple of two almosts.

If self is Value((a, b)) this method returns (Value(a), Value(b)). Otherwise, (Nil, Nil) is returned.

§Examples
let x = Value((1, "hi"));
let y = Nil::<(u8, u32)>;

assert_eq!(Almost::unzip(x), (Value(1), Value("hi")));
assert_eq!(Almost::unzip(y), (Nil, Nil));
Source§

impl<T> Almost<&T>

Source

pub const fn copied(this: Self) -> Almost<T>
where T: Copy,

Maps an Almost<&T> to an Almost<T> by copying the contents of the almost.

§Examples
let x = 12;
let opt_x = Value(&x);
assert_eq!(opt_x, Value(&12));
let copied = Almost::copied(opt_x);
assert_eq!(copied, Value(12));
Source

pub fn cloned(this: Self) -> Almost<T>
where T: Clone,

Maps an Almost<&T> to an Almost<T> by cloning the contents of the almost.

§Examples
let x = 12;
let opt_x = Value(&x);
assert_eq!(opt_x, Value(&12));
let cloned = Almost::cloned(opt_x);
assert_eq!(cloned, Value(12));
Source§

impl<T, E> Almost<Result<T, E>>

Source

pub fn transpose(this: Self) -> Result<Almost<T>, E>

Transposes an Almost of a Result into a Result of an Almost.

Nil will be mapped to Ok(Nil). Value(Ok(_)) and Value(Err(_)) will be mapped to Ok(Value(_)) and Err(_).

§Examples
#[derive(Debug, Eq, PartialEq)]
struct SomeErr;

let x: Result<Almost<i32>, SomeErr> = Ok(Value(5));
let y: Almost<Result<i32, SomeErr>> = Value(Ok(5));
assert_eq!(x, Almost::transpose(y));
Source§

impl<T> Almost<Almost<T>>

Source

pub fn flatten(this: Self) -> Almost<T>

Converts from Almost<Almost<T>> to Almost<T>.

§Examples

Basic usage:

let x: Almost<Almost<u32>> = Value(Value(6));
assert_eq!(Value(6), Almost::flatten(x));

let x: Almost<Almost<u32>> = Value(Nil);
assert_eq!(Nil, Almost::flatten(x));

let x: Almost<Almost<u32>> = Nil;
assert_eq!(Nil, Almost::flatten(x));

Flattening only removes one level of nesting at a time:

let x: Almost<Almost<Almost<u32>>> = Value(Value(Value(6)));
assert_eq!(Value(Value(6)), Almost::flatten(x));
assert_eq!(Value(6), Almost::flatten(Almost::flatten(x)));

Trait Implementations§

Source§

impl<U: ?Sized, T: AsRef<U>> AsRef<U> for Almost<T>

Source§

fn as_ref(&self) -> &U

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone> Clone for Almost<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Almost<T>

Source§

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

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

impl<T> Default for Almost<T>

Source§

fn default() -> Almost<T>

Returns the “default value” for a type. Read more
Source§

impl<T> Deref for Almost<T>

Source§

fn deref(&self) -> &Self::Target

Get a reference to the underlying data.

§Panic

Panics if self is Nil.

Source§

type Target = T

The resulting type after dereferencing.
Source§

impl<T> DerefMut for Almost<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Get a mutable reference to the underlying data.

§Panic

Panics if self is Nil.

Source§

impl<'a, T> From<&'a Almost<T>> for Almost<&'a T>

Source§

fn from(value: &'a Almost<T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T> From<&'a mut Almost<T>> for Almost<&'a mut T>

Source§

fn from(value: &'a mut Almost<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Almost<T>> for Option<T>

Source§

fn from(value: Almost<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Almost<T>

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Almost<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Almost<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T> IntoIterator for &'a Almost<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut Almost<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Almost<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: Ord> Ord for Almost<T>

Source§

fn cmp(&self, other: &Almost<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Almost<T>

Source§

fn eq(&self, other: &Almost<T>) -> 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.
Source§

impl<T: PartialOrd> PartialOrd for Almost<T>

Source§

fn partial_cmp(&self, other: &Almost<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy> Copy for Almost<T>

Source§

impl<T: Eq> Eq for Almost<T>

Source§

impl<T> StructuralPartialEq for Almost<T>

Auto Trait Implementations§

§

impl<T> Freeze for Almost<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Almost<T>
where T: RefUnwindSafe,

§

impl<T> Send for Almost<T>
where T: Send,

§

impl<T> Sync for Almost<T>
where T: Sync,

§

impl<T> Unpin for Almost<T>
where T: Unpin,

§

impl<T> UnwindSafe for Almost<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.