C ++ implementations obey the zero-cost principle: you do not pay for what you do not use [Straustrup, 1994]. Moreover: what you use is best coded.
- Bjarne Straustrup
Send
marker described in the previous post . They are used to declare "additional methods", that is, to add new methods to a type already defined somewhere. They replace traditional method overloading. They also provide an easy way to overload operators. struct Point { x: f64, y: f64, } // a free-standing function that converts a (borrowed) point to a string fn point_to_string(point: &Point) -> String { ... } // an "inherent impl" block defines the methods available directly on a type impl Point { // this method is available on any Point, and automatically borrows the // Point value fn to_string(&self) -> String { ... } }
to_string
, are called "own" because they are:impl
block),self
, &mut self
, or &self
- depending on the required level of ownership (it can be mut self
, but with respect to ownership it is the same as self
- comment perev.). Methods are called using a dot ( .
), As in a normal OOP, and the self parameter is implicitly borrowed if required by the method signature: let p = Point { x: 1.2, y: -3.7 }; let s1 = point_to_string(&p); // calling a free function, explicit borrow let s2 = p.to_string(); // calling a method, implicit borrow as &p
let child = Command::new("/bin/cat") .arg("rusty-ideas.txt") .current_dir("/Users/aturon") .stdout(Stdio::piped()) .spawn();
trait Hash { fn hash(&self) -> u64; }
hash
method with the appropriate signature: impl Hash for bool { fn hash(&self) -> u64 { if *self { 0 } else { 1 } } } impl Hash for i64 { fn hash(&self) -> u64 { *self as u64 } }
Hash
in the last example). That is, abstractions can be created as needed, and then applied to existing libraries.Hash
type is already in our scope, you can write true.hash()
. Thus, the type implementation extends the set of methods available for this type. fn print_hash<T: Hash>(t: &T) { println!("The hash is {}", t.hash()) }
print_hash
function print_hash
parameterized by an unknown type T
, but requires that this type implement the Hash
type. Which means that we can use it for values of bool
and i64
: print_hash(&true); // instantiates T = bool print_hash(&12_i64); // instantiates T = i64
print_hash
function: by version for each type used instead of the type argument. In turn, this means that the internal call to t.hash()
- the place where abstraction is used - has zero cost, since it will be compiled into a direct static call to the corresponding implementation of the hash
method: // The compiled code: __print_hash_bool(&true); // invoke specialized bool version directly __print_hash_i64(&12_i64); // invoke specialized i64 version directly
print_hash
, but it is very convenient for more realistic use of hashing. Suppose that we also have a type to compare for equality: trait Eq { fn eq(&self, other: &Self) -> bool; }
Self
type here will be replaced by the type for which this type is implemented; in the case of impl Eq for bool
it will correspond to the type bool
.)T
for which the types Eq
and Hash
should be implemented: struct HashMap<Key: Hash + Eq, Value> { ... }
HashMap
with specific Key
and Value
types will result in the creation of a separate specific HashMap
type, which means that a HashMap can contain keys and values directly in its buckets, without the use of indirect addressing. This saves space, reduces the number of pointer pointers, and allows you to more fully use the memory of the cache.HashMap
method will also be compiled into specialized for specified types of code. So there are no additional expenses for dispatching when calling the hash
and eq
methods. It also means that the optimizer will be able to work with completely specific code - that is, from the point of view of the optimizer, there are no abstractions. In particular, static dispatch allows inline type-parameterized methods.HashMap
by itself, its code is checked for types only once, for the correct use of abstract types of Hash
and Eq
, and not every time when using specific types. Which means both clearer and earlier compilation errors for library authors, as well as lower typing costs for users of the language (read “faster compilation”). trait ClickCallback { fn on_click(&self, x: i64, y: i64); }
struct Button<T: ClickCallback> { listeners: Vec<T>, ... }
ClickCallback
, and this is reflected in a specific type of button. This is not what we need! We want one particular type of Button
with a set of disparate event recipients, each of which can be of any specific type that implements the type ClickCallback
. struct Button { listeners: Vec<Box<ClickCallback>>, ... }
Box
(pointer to heap) or &
(any pointer anywhere).&ClickCallback
or Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Box «-» T
, ( ClickCallback
), , T
( on_click
). , , T
. Button
, .
— , . , . - « »: , , , .
, , , . :
. ClickCallback
, . , , (Huon Wilson) . API. :
struct Pair<A, B> { first: A, second: B } impl<A: Hash, B: Hash> Hash for Pair<A, B> { fn hash(&self) -> u64 { self.first.hash() ^ self.second.hash() } }
Pair
Hash
, , . , API, . , :
#[derive(Hash)] struct Pair<A, B> { .. }
. ( ), (extension methods) C#. : , , , ! . «», : Send
, Sync
, Copy
, Sized
. — , , -. , #[derive]
. , Send
, Send
. , — Send
. . , . , : , - , , . , . -, ad hoc : , API, . -, : , . . +
. , , , .
: , , .
— , — : 1.0 . :
. , : « - , Iterator
», . , , . . , . . , . , , , , ( , , ). , . (, Higher-kinded types, HKT). , ( Vec , Vec
— ). , . — , .
. , ( ), , , - ( DOM), GUI-, . — , (Niko Matsakis) . , , - .
, 1.0, - , , , . — , , . !
Source: https://habr.com/ru/post/257775/
All Articles