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§
Implementations§
Source§impl<T> Almost<T>
impl<T> Almost<T>
Sourcepub fn is_value_and(this: Self, f: impl FnOnce(T) -> bool) -> bool
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);Sourcepub fn is_nil_or(this: Self, f: impl FnOnce(T) -> bool) -> bool
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);Sourcepub const fn as_mut(this: &mut Self) -> Almost<&mut T>
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));Sourcepub const fn as_pin_ref(this: Pin<&Self>) -> Almost<Pin<&T>>
pub const fn as_pin_ref(this: Pin<&Self>) -> Almost<Pin<&T>>
Converts from Pin<&Almost<T>> to Almost<Pin<&T>>
Sourcepub const fn as_pin_mut(this: Pin<&mut Self>) -> Almost<Pin<&mut T>>
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>>
Sourcepub const fn as_slice(this: &Self) -> &[T]
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>), &[][..]);Sourcepub const fn as_slice_mut(this: &mut Self) -> &mut [T]
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 [][..]);Sourcepub fn expect(this: Self, msg: &str) -> T
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`§Recommended Message Style
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");Sourcepub fn unwrap(this: Self) -> T
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"); // failsSourcepub fn unwrap_or(this: Self, default: T) -> T
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");Sourcepub fn unwrap_or_else(this: Self, f: impl FnOnce() -> T) -> T
pub fn unwrap_or_else(this: Self, f: impl FnOnce() -> T) -> T
Sourcepub fn unwrap_or_default(this: Self) -> Twhere
T: Default,
pub fn unwrap_or_default(this: Self) -> Twhere
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);Sourcepub unsafe fn unwrap_unchecked(this: Self) -> T
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!Sourcepub fn map<U>(this: Self, f: impl FnOnce(T) -> U) -> Almost<U>
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);Sourcepub fn inspect(this: Self, f: impl FnOnce(&T)) -> Self
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.
Sourcepub fn map_or<U>(this: Self, default: U, f: impl FnOnce(T) -> U) -> U
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);Sourcepub fn map_or_else<U>(
this: Self,
default: impl FnOnce() -> U,
f: impl FnOnce(T) -> U,
) -> U
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);Sourcepub fn ok_or<E>(this: Self, error: E) -> Result<T, E>
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));Sourcepub fn ok_or_else<E>(this: Self, error: impl FnOnce() -> E) -> Result<T, E>
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));Sourcepub fn as_deref(this: &Self) -> Almost<&<T as Deref>::Target>where
T: Deref,
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);Sourcepub fn as_deref_mut(this: &mut Self) -> Almost<&mut <T as Deref>::Target>where
T: DerefMut,
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);Sourcepub fn into_option(this: Self) -> Option<T>
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);Sourcepub fn iter(this: &Self) -> Iter<'_, T> ⓘ
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);Sourcepub fn iter_mut(this: &mut Self) -> IterMut<'_, T> ⓘ
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);Sourcepub fn and<U>(this: Self, other: Almost<U>) -> Almost<U>
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);Sourcepub fn and_then<U>(this: Self, other: impl FnOnce(T) -> Almost<U>) -> Almost<U>
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);Sourcepub fn filter(this: Self, do_get: impl FnOnce(&T) -> bool) -> Self
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)ifpredicatereturnstrue(wheretis the wrapped value), andNilifpredicatereturnsfalse.
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));Sourcepub fn or(this: Self, other: Self) -> Self
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);Sourcepub fn or_else(this: Self, f: impl FnOnce() -> Self) -> Self
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);Sourcepub fn xor(this: Self, other: Self) -> Self
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);Sourcepub fn insert(this: &mut Self, value: T) -> &mut T
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);Sourcepub fn get_or_insert(this: &mut Self, value: T) -> &mut T
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));Sourcepub fn get_or_insert_default(this: &mut Self) -> &mut Twhere
T: Default,
pub fn get_or_insert_default(this: &mut Self) -> &mut Twhere
T: Default,
Sourcepub fn get_or_insert_with(this: &mut Self, f: impl FnOnce() -> T) -> &mut T
pub fn get_or_insert_with(this: &mut Self, f: impl FnOnce() -> T) -> &mut T
Sourcepub fn take_unwrap(this: &mut Self) -> T
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);Sourcepub fn take_expect(this: &mut Self, message: &str) -> T
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");Sourcepub fn take_if(this: &mut Self, f: impl FnOnce(&mut T) -> bool) -> Self
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));Sourcepub const fn replace(this: &mut Self, value: T) -> Self
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);Sourcepub fn zip<U>(this: Self, other: Almost<U>) -> Almost<(T, U)>
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);Sourcepub fn zip_with<U, R>(
this: Self,
other: Almost<U>,
f: impl FnOnce(T, U) -> R,
) -> Almost<R>
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);Sourcepub fn from_option(value: Option<T>) -> Self
pub fn from_option(value: Option<T>) -> Self
Source§impl<T, U> Almost<(T, U)>
impl<T, U> Almost<(T, U)>
Sourcepub fn unzip(this: Self) -> (Almost<T>, Almost<U>)
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>
impl<T> Almost<&T>
Source§impl<T, E> Almost<Result<T, E>>
impl<T, E> Almost<Result<T, E>>
Sourcepub fn transpose(this: Self) -> Result<Almost<T>, E>
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>>
impl<T> Almost<Almost<T>>
Sourcepub fn flatten(this: Self) -> Almost<T>
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)));