1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Module providing utility traits for encoding CAN-bus data.
//!
//! The module provides two traits: [TryEncode], and [Encode]. [try_encode](TryEncode::try_encode)
//! models the possibility that the encoding fails whereas [encode](Encode::encode) models the not
//! failable encoding. If [encode](Encode::encode) fails internally, it panics.
//!
//! # Example
//! ```
//! use cantools::data::CANRead;
//! use cantools::signals::Bit;
//! use cantools::encode::{TryEncode, Encode};
//!
//! let bit = Bit::new(20);
//! let mut data = [0u8, 0u8, 0u8, 0u8];
//!
//! let result = bit.try_encode(&mut data, true);
//! bit.encode(&mut data, false);
//! ```
use crateCANWrite;
/// Type representing possible encoding errors.
/// A trait modeling the failable encoding of data.
/// A trait modeling the not failable encoding of data.
///
/// [Encode] is sub-trait of [TryEncode]. [encode](Encode::encode) is implemented using
/// [try_encode](TryEncode::try_encode). If [try_encode](TryEncode::try_encode) succeeds,
/// [encode](Encode::encode) returns. Otherwise, [encode](Encode::encode) panics.