В
Iterator и Node в данном контекстеSize: a a a
В
Iterator и Node в данном контекстеAZ
В
Entry — тип, а не трейт, там не может быть ассоциированных типовV
trait Node {
type Item;
}
struct Nil<T>(PhantomData<T>);
impl<T> Node for Nil<T> {
type Item = T;
}
struct Cons<N: Node> {
head: N::Item,
tail: N,
}
impl<N: Node> Node for Cons<N> {
type Item = N::Item;
}
(playground)#[derive(Debug)]
struct LinkedList<T, U> {
head: T,
tail: U,
}
fn end<T>(head: T) -> LinkedList<T,()> {
LinkedList {
head: head,
tail: (),
}
}
fn cons<T,U>(head: T, tail: LinkedList<T, U>) -> LinkedList<T, LinkedList<T, U>> {
LinkedList {
head,
tail
}
}
fn main() {
let list = cons(10, cons(20, end(1)));
println!("{:?}", list);
}
AZ
trait Node {
type Item;
}
struct Nil<T>(PhantomData<T>);
impl<T> Node for Nil<T> {
type Item = T;
}
struct Cons<N: Node> {
head: N::Item,
tail: N,
}
impl<N: Node> Node for Cons<N> {
type Item = N::Item;
}
(playground)В
#[derive(Debug)]
struct LinkedList<T, U> {
head: T,
tail: U,
}
fn end<T>(head: T) -> LinkedList<T,()> {
LinkedList {
head: head,
tail: (),
}
}
fn cons<T,U>(head: T, tail: LinkedList<T, U>) -> LinkedList<T, LinkedList<T, U>> {
LinkedList {
head,
tail
}
}
fn main() {
let list = cons(10, cons(20, end(1)));
println!("{:?}", list);
}
LinkedList<i32, LinkedList<bool, ()>> (то что ты не можешь создать такое вне модуля — другой вопрос)V
LinkedList<i32, LinkedList<bool, ()>> (то что ты не можешь создать такое вне модуля — другой вопрос)V
...
#[derive(Debug)]
struct X;
impl Node<i32> for X {}
fn main() {
let list = cons(10, cons(20, X));
println!("{:?}", list);
}
В
Sealed в помощьV
Sealed в помощьV
KR
foo.as_mut().unwrap_or_default().push(bar)?Option<&mut T> автоматически сеттил T::default() если там None.KR
MB
foo.as_mut().unwrap_or_default().push(bar)?Option<&mut T> автоматически сеттил T::default() если там None.KR
&mut туда, где его ожидали.KR
R
C
NN