comparison rust/hg-core/src/revlog/node.rs @ 46435:2e2033081274

rust: replace trivial `impl From …` with `#[derive(derive_more::From)]` Crate docs: https://jeltef.github.io/derive_more/derive_more/from.html Differential Revision: https://phab.mercurial-scm.org/D9875
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 26 Jan 2021 20:05:37 +0100
parents 645ee7225fab
children 43d63979a75e
comparison
equal deleted inserted replaced
46434:3e2d539d0d1a 46435:2e2033081274
47 /// 47 ///
48 /// All methods that create a `Node` either take a type that enforces 48 /// All methods that create a `Node` either take a type that enforces
49 /// the size or return an error at runtime. 49 /// the size or return an error at runtime.
50 /// 50 ///
51 /// [`nybbles_len`]: #method.nybbles_len 51 /// [`nybbles_len`]: #method.nybbles_len
52 #[derive(Copy, Clone, Debug, PartialEq, BytesCast)] 52 #[derive(Copy, Clone, Debug, PartialEq, BytesCast, derive_more::From)]
53 #[repr(transparent)] 53 #[repr(transparent)]
54 pub struct Node { 54 pub struct Node {
55 data: NodeData, 55 data: NodeData,
56 } 56 }
57 57
58 /// The node value for NULL_REVISION 58 /// The node value for NULL_REVISION
59 pub const NULL_NODE: Node = Node { 59 pub const NULL_NODE: Node = Node {
60 data: [0; NODE_BYTES_LENGTH], 60 data: [0; NODE_BYTES_LENGTH],
61 }; 61 };
62
63 impl From<NodeData> for Node {
64 fn from(data: NodeData) -> Node {
65 Node { data }
66 }
67 }
68 62
69 /// Return an error if the slice has an unexpected length 63 /// Return an error if the slice has an unexpected length
70 impl<'a> TryFrom<&'a [u8]> for &'a Node { 64 impl<'a> TryFrom<&'a [u8]> for &'a Node {
71 type Error = (); 65 type Error = ();
72 66