Queue

Struct Queue 

Source
pub struct Queue<Front, Back>
where Back: StQueue,
{ /* private fields */ }
Expand description

A queue containing multiple (>= 2) elements.

It is composed of two parts:

  • f: Front is the element in the front of the queue;
  • b: Back is the queue of remaining elements except for the one in the front. It can be:
    • either a QueueSingle containing exactly one element in which case length of this queue is 2,
    • or a Queue containing multiple elements, in which case length of this queue is greater than 2, 1 + self.b.len().

Note that Queue::new(element) gives a QueueSingle with one element. In order to create a queue of multiple elements, we need to push at least one more element, such as Queue::new(elem1).push(elem2).

Implementations§

Source§

impl<F> Queue<F, QueueSingle<F>>

Source

pub fn new(element: F) -> QueueSingle<F>

Creates a QueueSingle with exactly one element.

Note that Queue::new is equivalent to QueueSingle::new. It is introduced for convenience allowing us to work only with the multiple element queue type Queue.

§Examples
use orx_meta::queue::*;
use orx_meta::queue_of;

// creates a QueueSingle
let queue: QueueSingle<u32> = Queue::new(42);
assert_eq!(queue.len(), 1);
assert_eq!(queue.front(), &42);

// creates a Queue when we push at least one more element
let queue: Queue<u32, QueueSingle<char>> = Queue::new(42).push('x');
assert_eq!(queue.len(), 2);

let queue: Queue<u32, Queue<char, Queue<bool, QueueSingle<String>>>>
  = Queue::new(42).push('x').push(true).push("foo".to_string());
assert_eq!(queue.as_tuple(), (&42, &'x', &true, &"foo".to_string()));

// equivalently, we can use the queue_of macro to create the type
let queue: queue_of!(u32, char, bool, String)
  = Queue::new(42).push('x').push(true).push("foo".to_string());
assert_eq!(queue.as_tuple(), (&42, &'x', &true, &"foo".to_string()));
Source§

impl<F, B> Queue<F, B>
where B: StQueue,

Source

pub fn back(&self) -> &B

Returns a reference to the queue including elements of this queue excluding the element in the front.

Note that accessing elements of the queue is always by front, while back allows to access elements in all positions of the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.front(), &42);
// assert_eq!(queue.back(), ??); // wont' compile, QueueSingle has no back

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.back(), &Queue::new(true).push('x').push("foo"));
assert_eq!(queue.front(), &42);
assert_eq!(queue.back().front(), &true);
assert_eq!(queue.back().back().front(), &'x');
assert_eq!(queue.back().back().back().front(), &"foo");

let (num, queue) = queue.pop();
assert_eq!(num, 42);
assert_eq!(queue.front(), &true);
assert_eq!(queue.back(), &Queue::new('x').push("foo"));

let (flag, queue) = queue.pop();
assert_eq!(flag, true);
assert_eq!(queue.front(), &'x');
assert_eq!(queue.back(), &Queue::new("foo"));

let (c, queue) = queue.pop();
assert_eq!(c, 'x');
assert_eq!(queue.front(), &"foo");
// assert_eq!(queue.back(), ??);  // wont' compile, QueueSingle has no back

let s = queue.pop();
assert_eq!(s, "foo");
Source

pub fn back_mut(&mut self) -> &mut B

Returns a mutable reference to the queue including elements of this queue excluding the element in the front.

Note that mutating elements of the queue is always by front_mut, while back_mut allows to access elements in all positions of the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42).push(true).push('x');

*queue.front_mut() *= 2;
*queue.back_mut().front_mut() = false;
*queue.back_mut().back_mut().front_mut() = 'y';

assert_eq!(queue.as_tuple(), (&84, &false, &'y'));
Source

pub fn front_back_mut(&mut self) -> (&mut F, &mut B)

Returns a pair of mutable references:

  • first to the element in the front of the queue, and
  • second to the back queue containing elements except for the front.
§Safety

Assume we have a queue of three elements and we want to mutate the first and third elements as follows.

However, the following code would not compile.

use orx_meta::queue::*;

let mut q = Queue::new(3).push(true).push('x');

let first = q.front_mut();
let third = q.back_mut().back_mut().front_mut();

// these calls can be made concurrently
*first *= 2;
*third = 'y';

It is perfectly safe to mutate the first and third elements at the same time. Actually, we can mutate all of the elements concurrently.

However, we need to help the compiler to figure this out, which is why we get the mutable references to the front and back at the same time. With this, the compiler understands that there is no overlap between them.

§Examples

So the following code would compile and work expectedly.

use orx_meta::queue::*;

let mut q = Queue::new(3).push(true).push('x');

let (first, q23) = q.front_back_mut();
let third = q23.back_mut().front_mut();

// these calls can be made concurrently
*first *= 2;
*third = 'y';

assert_eq!(q.as_tuple(), (&6, &true, &'y'));
Source

pub fn into_back(self) -> B

Consumes the queue and returns the queue including elements of this queue except for the element in the front.

Equivalent to queue.pop().1.

Source

pub fn pop(self) -> (F, B)

Consumes the queue and returns the tuple of its front and back:

  • front is the element in the front of this queue.
  • back is the queue including all elements of this queue except for the front element. In other words, it is the queue obtained by popping the front element.
§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
let num = queue.pop(); // QueueSingle::pop just returns the front
assert_eq!(num, 42);

let queue = Queue::new(42).push(true).push('x').push("foo");

let (num, queue) = queue.pop(); // Queue::pop returns (front, back)
assert_eq!(num, 42);
assert_eq!(queue, Queue::new(true).push('x').push("foo"));

let (flag, queue) = queue.pop();
assert_eq!(flag, true);
assert_eq!(queue, Queue::new('x').push("foo"));

let (c, queue) = queue.pop();
assert_eq!(c, 'x');
assert_eq!(queue, Queue::new("foo"));

let s = queue.pop();
assert_eq!(s, "foo");
Source§

impl<X1, X2> Queue<X1, QueueSingle<X2>>

Source

pub fn into_tuple(self) -> (X1, X2)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<X1, X2, X3> Queue<X1, Queue<X2, QueueSingle<X3>>>

Source

pub fn into_tuple(self) -> (X1, X2, X3)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2, &X3)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<X1, X2, X3, X4> Queue<X1, Queue<X2, Queue<X3, QueueSingle<X4>>>>

Source

pub fn into_tuple(self) -> (X1, X2, X3, X4)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<X1, X2, X3, X4, X5> Queue<X1, Queue<X2, Queue<X3, Queue<X4, QueueSingle<X5>>>>>

Source

pub fn into_tuple(self) -> (X1, X2, X3, X4, X5)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<X1, X2, X3, X4, X5, X6> Queue<X1, Queue<X2, Queue<X3, Queue<X4, Queue<X5, QueueSingle<X6>>>>>>

Source

pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut( &mut self, ) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<X1, X2, X3, X4, X5, X6, X7> Queue<X1, Queue<X2, Queue<X3, Queue<X4, Queue<X5, Queue<X6, QueueSingle<X7>>>>>>>

Source

pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6, X7)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6, &X7)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut( &mut self, ) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6, &mut X7)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
Source§

impl<X1, X2, X3, X4, X5, X6, X7, X8> Queue<X1, Queue<X2, Queue<X3, Queue<X4, Queue<X5, Queue<X6, Queue<X7, QueueSingle<X8>>>>>>>>

Source

pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6, X7, X8)

Converts the queue into its flat tuple representation.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.into_tuple(), 42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.into_tuple(), (42, true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
Source

pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6, &X7, &X8)

Returns a flat tuple representation of references to elements in the queue.

§Examples
use orx_meta::queue::*;

let queue = Queue::new(42);
assert_eq!(queue.as_tuple(), &42);

let queue = Queue::new(42).push(true);
assert_eq!(queue.as_tuple(), (&42, &true));

let queue = Queue::new(42).push(true).push('x').push("foo");
assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
Source

pub fn as_tuple_mut( &mut self, ) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6, &mut X7, &mut X8)

Returns a flat tuple representation of mutable references to elements in the queue.

§Examples
use orx_meta::queue::*;

let mut queue = Queue::new(42);
let a = queue.as_tuple_mut();
*a *= 2;
assert_eq!(queue.as_tuple(), &84);

let mut queue = Queue::new(42).push(true);
let (a, b) = queue.as_tuple_mut();
*a *= 2;
*b = false;
assert_eq!(queue.as_tuple(), (&84, &false));

let mut queue = Queue::new(42).push(true).push('x').push("foo");
let (a, b, c, d) = queue.as_tuple_mut();
*a *= 2;
*b = false;
*c = 'y';
*d = "bar";
assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));

Trait Implementations§

Source§

impl<Front: Clone, Back> Clone for Queue<Front, Back>
where Back: StQueue + Clone,

Source§

fn clone(&self) -> Queue<Front, Back>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<Front: Debug, Back> Debug for Queue<Front, Back>
where Back: StQueue + Debug,

Source§

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

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

impl<Front: PartialEq, Back> PartialEq for Queue<Front, Back>
where Back: StQueue + PartialEq,

Source§

fn eq(&self, other: &Queue<Front, Back>) -> 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<F, B> StQueue for Queue<F, B>
where B: StQueue,

Source§

const LEN: usize

Number of elements in the queue.
Source§

type PushBack<Elem> = Queue<F, <B as StQueue>::PushBack<Elem>>

Type of the queue obtained by adding an element of type Elem to this queue.
Source§

type Front = F

Type of the element at the front of the queue.
Source§

type Back = B

Type of the queue that would be obtained by popping the Front element of the queue.
Source§

fn front(&self) -> &F

Returns a reference to the element in the front of the queue. Read more
Source§

fn front_mut(&mut self) -> &mut F

Returns a mutable reference to the element in the front of the queue. Read more
Source§

fn into_front(self) -> F

Consumes the queue and returns the element in the front of the queue. Read more
Source§

fn push<Elem>(self, element: Elem) -> Self::PushBack<Elem>

Pushes the element and returns the resulting queue. Read more
Source§

fn len(&self) -> usize

Pushes the element and returns the resulting queue. Read more
Source§

impl<Front: Copy, Back> Copy for Queue<Front, Back>
where Back: StQueue + Copy,

Source§

impl<Front: Eq, Back> Eq for Queue<Front, Back>
where Back: StQueue + Eq,

Source§

impl<Front, Back> StructuralPartialEq for Queue<Front, Back>
where Back: StQueue,

Auto Trait Implementations§

§

impl<Front, Back> Freeze for Queue<Front, Back>
where Front: Freeze, Back: Freeze,

§

impl<Front, Back> RefUnwindSafe for Queue<Front, Back>
where Front: RefUnwindSafe, Back: RefUnwindSafe,

§

impl<Front, Back> Send for Queue<Front, Back>
where Front: Send, Back: Send,

§

impl<Front, Back> Sync for Queue<Front, Back>
where Front: Sync, Back: Sync,

§

impl<Front, Back> Unpin for Queue<Front, Back>
where Front: Unpin, Back: Unpin,

§

impl<Front, Back> UnwindSafe for Queue<Front, Back>
where Front: UnwindSafe, Back: 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<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<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.