Skip to content

Commit

Permalink
Fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed May 21, 2023
1 parent 80fd962 commit be09b1f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 33 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ deemed unnecessary, such as [when decoding collections]. The result is
usually cleaner decode implementations, as shown here:

```rust
use musli::Context;
use musli::de::{Decode, Decoder, SequenceDecoder};
use musli::mode::Mode;

Expand All @@ -121,18 +122,19 @@ struct MyType {
}

impl<'de, M> Decode<'de, M> for MyType where M: Mode {
fn decode<D>(decoder: D) -> Result<Self, D::Error>
fn decode<'buf, C, D>(cx: &mut C, decoder: D) -> Result<Self, C::Error>
where
C: Context<'buf, Input = D::Error>,
D: Decoder<'de>,
{
let mut seq = decoder.decode_sequence()?;
let mut seq = decoder.decode_sequence(cx)?;
let mut data = Vec::with_capacity(seq.size_hint().or_default());

while let Some(decoder) = seq.next()? {
data.push(Decode::<M>::decode(decoder)?);
while let Some(decoder) = seq.next(cx)? {
data.push(Decode::<M>::decode(cx, decoder)?);
}

seq.end()?;
seq.end(cx)?;

Ok(Self {
data
Expand Down Expand Up @@ -403,18 +405,18 @@ cannot) make stricter assumptions as a result.
[^i128]: Lacks 128-bit support.

[`bincode`]: https://docs.rs/bincode
[`Decode`]: https://docs.rs/musli/latest/musli/trait.Decode.html
[`Decode`]: https://docs.rs/musli/latest/musli/de/trait.Decode.html
[`DefaultMode`]: https://docs.rs/musli/latest/musli/mode/enum.DefaultMode.html
[`derives`]: https://docs.rs/musli/latest/musli/derives/
[`Encode`]: https://docs.rs/musli/latest/musli/trait.Encode.html
[`Encode`]: https://docs.rs/musli/latest/musli/en/trait.Encode.html
[`musli-descriptive`]: https://docs.rs/musli-descriptive
[`musli-json`]: https://docs.rs/musli-json
[`musli-storage`]: https://docs.rs/musli-storage
[`musli-tests`]: https://github.com/udoprog/musli/tree/main/crates/musli-tests
[`musli-value`]: https://docs.rs/musli-value
[`musli-wire`]: https://docs.rs/musli-wire
[`musli-json`]: https://docs.rs/musli-json
[`protobuf`]: https://developers.google.com/protocol-buffers
[`serde`]: https://serde.rs
[`simdutf8`]: https://docs.rs/simdutf8
[bit packing]: https://github.com/udoprog/musli/blob/main/crates/musli-descriptive/src/tag.rs
[when decoding collections]: https://docs.rs/serde/latest/serde/trait.Deserializer.html#tymethod.deserialize_seq
[`simdutf8`]: https://docs.rs/simdutf8
20 changes: 11 additions & 9 deletions crates/musli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ deemed unnecessary, such as [when decoding collections]. The result is
usually cleaner decode implementations, as shown here:

```rust
use musli::Context;
use musli::de::{Decode, Decoder, SequenceDecoder};
use musli::mode::Mode;

Expand All @@ -121,18 +122,19 @@ struct MyType {
}

impl<'de, M> Decode<'de, M> for MyType where M: Mode {
fn decode<D>(decoder: D) -> Result<Self, D::Error>
fn decode<'buf, C, D>(cx: &mut C, decoder: D) -> Result<Self, C::Error>
where
C: Context<'buf, Input = D::Error>,
D: Decoder<'de>,
{
let mut seq = decoder.decode_sequence()?;
let mut seq = decoder.decode_sequence(cx)?;
let mut data = Vec::with_capacity(seq.size_hint().or_default());

while let Some(decoder) = seq.next()? {
data.push(Decode::<M>::decode(decoder)?);
while let Some(decoder) = seq.next(cx)? {
data.push(Decode::<M>::decode(cx, decoder)?);
}

seq.end()?;
seq.end(cx)?;

Ok(Self {
data
Expand Down Expand Up @@ -403,18 +405,18 @@ cannot) make stricter assumptions as a result.
[^i128]: Lacks 128-bit support.

[`bincode`]: https://docs.rs/bincode
[`Decode`]: https://docs.rs/musli/latest/musli/trait.Decode.html
[`Decode`]: https://docs.rs/musli/latest/musli/de/trait.Decode.html
[`DefaultMode`]: https://docs.rs/musli/latest/musli/mode/enum.DefaultMode.html
[`derives`]: https://docs.rs/musli/latest/musli/derives/
[`Encode`]: https://docs.rs/musli/latest/musli/trait.Encode.html
[`Encode`]: https://docs.rs/musli/latest/musli/en/trait.Encode.html
[`musli-descriptive`]: https://docs.rs/musli-descriptive
[`musli-json`]: https://docs.rs/musli-json
[`musli-storage`]: https://docs.rs/musli-storage
[`musli-tests`]: https://github.com/udoprog/musli/tree/main/crates/musli-tests
[`musli-value`]: https://docs.rs/musli-value
[`musli-wire`]: https://docs.rs/musli-wire
[`musli-json`]: https://docs.rs/musli-json
[`protobuf`]: https://developers.google.com/protocol-buffers
[`serde`]: https://serde.rs
[`simdutf8`]: https://docs.rs/simdutf8
[bit packing]: https://github.com/udoprog/musli/blob/main/crates/musli-descriptive/src/tag.rs
[when decoding collections]: https://docs.rs/serde/latest/serde/trait.Deserializer.html#tymethod.deserialize_seq
[`simdutf8`]: https://docs.rs/simdutf8
4 changes: 2 additions & 2 deletions crates/musli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ pub trait Context<'buf> {

/// For named (string) variants, stores the tag string in the context.
///
/// It should be possible to recall the string later using [`take_string`].
/// It should be possible to recall the string later using [`get_string`].
///
/// [`take_string`]: Context::take_string
/// [`get_string`]: Context::get_string
#[allow(unused_variables)]
#[inline(always)]
fn store_string(&mut self, string: &str) {}
Expand Down
6 changes: 4 additions & 2 deletions crates/musli/src/de/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use core::fmt;
/// Indicates that an error occurred during decoding. This is a placeholder
/// error that can be used by context implementations and is a ZST.
///
/// Using it directly as a musli [Error][crate::error::Error] is not a good
/// idea, since it discards any diagnostics provided to it.
/// Using it directly as a musli [`Error`] is not a good idea, since it discards
/// any diagnostics provided to it.
///
/// Error details are expected to be reported to the corresponding [`Context`].
///
/// [`Context`]: crate::context::Context
#[derive(Debug)]
pub struct Error;

Expand Down
16 changes: 9 additions & 7 deletions crates/musli/src/derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
//!
//! #### `#[musli(trace)]`
//!
//! This causes the field to use the [`DecodeTrace`] / [`EncodeTrace`] when
//! This causes the field to use the [`TraceDecode`] / [`TraceEncode`] when
//! encoding the field. This is left optional for types where enabling tracing
//! for the field requires extra traits to be implemented, such as `HashMap<K,
//! V>` where we'd need `K` to implement `fmt::Display`.
Expand Down Expand Up @@ -824,14 +824,16 @@
//! a map for the field corresponding to the `tag`, and then use this to
//! determine which decoder implementation to call.
//!
//! [default mode]: crate::mode::DefaultMode
//! [`Decode`]: crate::Decode
//! [`Decoder::decode_buffer`]: crate::Decoder::decode_buffer
//! [`Decoder::decode_variant`]: crate::Decoder::decode_variant
//! [`Decoder`]: crate::Decoder
//! [`DefaultMode`]: crate::mode::DefaultMode
//! [`Encode`]: crate::Encode
//! [`Decode`]: crate::Decode
//! [`Encoder`]: crate::Encoder
//! [`Encoder::encode_variant`]: crate::Encoder::encode_variant
//! [`Decoder`]: crate::Decoder
//! [`Decoder::decode_variant`]: crate::Decoder::decode_variant
//! [`Decoder::decode_buffer`]: crate::Decoder::decode_buffer
//! [`Encoder`]: crate::Encoder
//! [`TraceDecode`]: crate::de::TraceDecode
//! [`TraceEncode`]: crate::en::TraceEncode
//! [default mode]: crate::mode::DefaultMode
// Parts of this documentation
8 changes: 4 additions & 4 deletions crates/musli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,21 @@
//! [^i128]: Lacks 128-bit support.
//!
//! [`bincode`]: https://docs.rs/bincode
//! [`Decode`]: https://docs.rs/musli/latest/musli/trait.Decode.html
//! [`Decode`]: https://docs.rs/musli/latest/musli/de/trait.Decode.html
//! [`DefaultMode`]: https://docs.rs/musli/latest/musli/mode/enum.DefaultMode.html
//! [`derives`]: https://docs.rs/musli/latest/musli/derives/
//! [`Encode`]: https://docs.rs/musli/latest/musli/trait.Encode.html
//! [`Encode`]: https://docs.rs/musli/latest/musli/en/trait.Encode.html
//! [`musli-descriptive`]: https://docs.rs/musli-descriptive
//! [`musli-json`]: https://docs.rs/musli-json
//! [`musli-storage`]: https://docs.rs/musli-storage
//! [`musli-tests`]: https://github.com/udoprog/musli/tree/main/crates/musli-tests
//! [`musli-value`]: https://docs.rs/musli-value
//! [`musli-wire`]: https://docs.rs/musli-wire
//! [`musli-json`]: https://docs.rs/musli-json
//! [`protobuf`]: https://developers.google.com/protocol-buffers
//! [`serde`]: https://serde.rs
//! [`simdutf8`]: https://docs.rs/simdutf8
//! [bit packing]: https://github.com/udoprog/musli/blob/main/crates/musli-descriptive/src/tag.rs
//! [when decoding collections]: https://docs.rs/serde/latest/serde/trait.Deserializer.html#tymethod.deserialize_seq
//! [`simdutf8`]: https://docs.rs/simdutf8
#![deny(missing_docs)]
#![no_std]
Expand Down

0 comments on commit be09b1f

Please sign in to comment.