Skip to content

Commit 3909a94

Browse files
committed
Updated crate documentation
1 parent e347a49 commit 3909a94

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ allocations and unnecessary copies.
1919

2020
## Example
2121
```rust
22-
use asn1_der::{
23-
DerObject,
24-
typed::{ DerEncodable, DerDecodable }
22+
use asn1_der::{
23+
DerObject,
24+
typed::{ DerEncodable, DerDecodable }
2525
};
2626

27-
fn main() {
28-
const INT7: &'static[u8] = b"\x02\x01\x07";
27+
/// An ASN.1-DER encoded integer `7`
28+
const INT7: &'static[u8] = b"\x02\x01\x07";
2929

30-
// Decode an arbitrary DER object
31-
let object = DerObject::decode(INT7).expect("Failed to decode object");
30+
// Decode an arbitrary DER object
31+
let object = DerObject::decode(INT7).expect("Failed to decode object");
3232

33-
// Encode an arbitrary DER object
34-
let mut encoded_object = Vec::new();
35-
object.encode(&mut encoded_object).expect("Failed to encode object");
33+
// Encode an arbitrary DER object
34+
let mut encoded_object = Vec::new();
35+
object.encode(&mut encoded_object).expect("Failed to encode object");
3636

37-
// Decode a `u8`
38-
let number = u8::decode(INT7).expect("Failed to decode string");
37+
// Decode a `u8`
38+
let number = u8::decode(INT7).expect("Failed to decode string");
39+
assert_eq!(number, 7);
3940

40-
// Encode a new `u8`
41-
let mut encoded_number = Vec::new();
42-
7u8.encode(&mut encoded_number).expect("Failed to encode string");
43-
}
41+
// Encode a new `u8`
42+
let mut encoded_number = Vec::new();
43+
7u8.encode(&mut encoded_number).expect("Failed to encode string");
4444
```
4545

4646
For the (de-)serialization of structs and similar via `derive`, see
@@ -75,7 +75,7 @@ of errors that can also happen in this crate. This especially includes:
7575
be omitted if `no_panic` is enabled.
7676

7777
This crate might allocate memory in the following circumstances:
78-
- When writing to a dynamically allocating sink (e.g. `Vec<u8>`)
78+
- When writing to a dynamically allocating sink (e.g. `Vec<u8>`, `VecBacking(Vec<u8>)`)
7979
- When decoding a native owned type such as `Vec<u8>`, `SequenceVec(Vec<T>)` or `String`
8080
- During error propagation
8181

@@ -95,6 +95,7 @@ Due to the limitations described above, the following functions are mutually exc
9595
`no_panic` and disabled if `no_panic` is set:
9696
- Error stacking/propagation (`propagate` is a no-op if compiled with `no_panic`)
9797
- The sink implementation for a byte vector (`impl Sink for Vec<u8>`)
98+
- The `VecBacking(Vec<u8>)` type
9899
- The native OctetString type which uses `Vec<u8>` (`impl<'a> DerDecodable<'a> for Vec<u8>` and
99100
`impl DerEncodable for Vec<u8>`)
100101
- The native Sequence type wrapper `SequenceVec` since it is based upon `Vec`

src/lib.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
//!
1919
//!
2020
//! ## Example
21-
//! ```
22-
//! # #[cfg(all(feature = "native_types", not(any(feature = "no_std", feature = "no_panic"))))] {
21+
//! ```rust
2322
//! use asn1_der::{
24-
//! DerObject,
25-
//! typed::{ DerEncodable, DerDecodable }
23+
//! DerObject,
24+
//! typed::{ DerEncodable, DerDecodable }
2625
//! };
2726
//!
2827
//! /// An ASN.1-DER encoded integer `7`
@@ -42,7 +41,6 @@
4241
//! // Encode a new `u8`
4342
//! let mut encoded_number = Vec::new();
4443
//! 7u8.encode(&mut encoded_number).expect("Failed to encode string");
45-
//! # }
4644
//! ```
4745
//!
4846
//! For the (de-)serialization of structs and similar via `derive`, see
@@ -53,8 +51,8 @@
5351
//! There are also some direct `DerDecodable`/`DerDecodable` implementations for native Rust type
5452
//! equivalents:
5553
//! - The ASN.1-`BOOLEAN` type as Rust-`bool`
56-
//! - The ASN.1-`INTEGER` type as Rust-[`u8`, `u16`, `u32`, `u64`, `u128`, `usize`, `i8`, `i16`,
57-
//! `i32`, `i64`, `i128`, `isize`]
54+
//! - The ASN.1-`INTEGER` type as Rust-[`u8`, `u16`, `u32`, `u64`, `u128`, `usize`,
55+
//! `i8`, `i16`, `i32`, `i64`, `i128`, `isize`]
5856
//! - The ASN.1-`NULL` type as either `()` or `Option::None` (which allows the encoding of
5957
//! optionals)
6058
//! - The ASN.1-`OctetString` type as `Vec<u8>`
@@ -77,7 +75,7 @@
7775
//! `no_panic` and will be omitted if `no_panic` is enabled.
7876
//!
7977
//! This crate might allocate memory in the following circumstances:
80-
//! - When writing to a dynamically allocating sink (e.g. `Vec<u8>`)
78+
//! - When writing to a dynamically allocating sink (e.g. `Vec<u8>`, `VecBacking(Vec<u8>)`)
8179
//! - When decoding a native owned type such as `Vec<u8>`, `SequenceVec(Vec<T>)` or `String`
8280
//! - During error propagation
8381
//!
@@ -93,11 +91,22 @@
9391
//!
9492
//! This crate by itself does never call `abort` directly.
9593
//!
94+
//! Due to the limitations described above, the following functions are mutually exclusive to
95+
//! `no_panic` and disabled if `no_panic` is set:
96+
//! - Error stacking/propagation (`propagate` is a no-op if compiled with `no_panic`)
97+
//! - The sink implementation for a byte vector (`impl Sink for Vec<u8>`)
98+
//! - The `VecBacking(Vec<u8>)` type
99+
//! - The native OctetString type which uses `Vec<u8>` (`impl<'a> DerDecodable<'a> for Vec<u8>` and
100+
//! `impl DerEncodable for Vec<u8>`)
101+
//! - The native Sequence type wrapper `SequenceVec` since it is based upon `Vec`
102+
//! - The native Utf8String type based upon `String` (`impl<'a> DerDecodable<'a> for String` and
103+
//! `impl DerEncodable for String`)
104+
//!
96105
//!
97106
//! ## Zero-Copy
98107
//! The crate is designed to be as much zero-copy as possible. In fact this means that the
99108
//! `DerObject` type and all typed views are zero-copy views over the underlying slice. Of course,
100-
//! zero-copy is not always reasonable: The `new`-constructors are not zero-copy because they
109+
//! ero-copy is not always reasonable: The `new`-constructors are not zero-copy because they
101110
//! construct a new object into a sink and the native type implementations are not zero-copy because
102111
//! they are either `Copy`-types (e.g. `u128`) or owned (e.g. `String`).
103112
//!
@@ -122,7 +131,8 @@
122131
#[doc(hidden)]
123132
pub mod error;
124133
mod data;
125-
mod der;
134+
#[doc(hidden)]
135+
pub mod der;
126136
#[cfg(feature = "native_types")]
127137
pub mod typed;
128138

0 commit comments

Comments
 (0)