Skip to content
Merged
6 changes: 6 additions & 0 deletions parity-bytes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ description = "byte utilities for Parity"
license = "GPL-3.0"

[dependencies]


[features]
default = ["std","nostd"]
std = []
nostd = []
Comment thread
ordian marked this conversation as resolved.
Outdated
25 changes: 22 additions & 3 deletions parity-bytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,28 @@
//! Includes a pretty-printer for bytes, in the form of `ToPretty` and `PrettySlice`
//! as

use std::fmt;
use std::cmp::min;
use std::ops::{Deref, DerefMut};
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
Comment thread
ordian marked this conversation as resolved.

#[cfg(not(feature = "std"))]
extern crate alloc;

// Re-export libcore using an alias so that the macros can work without
// requiring `extern crate core` downstream.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand what you mean by "the macros" – are there macros exported from this crate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it from the elastic-array and it have some marcos exported.
https://github.com/debris/elastic-array/blob/8f01572f850e6f387ad785fb1e59d599eb260ea0/src/lib.rs#L11-L28

I'm not sure whether will be some macros exported from this crate, so I didn't delete it 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we’re not doing it for the macros, then what is the purpose of this re-export? Can we remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed. 👌

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think you need to do:

#[cfg(feature = "std")]
extern crate core;

(notice no pub)

…and then replace use core_::{… … with use core::{… ….

The idea is that when running with std you need to import the core as a crate. In no_std mode core is part of the prelude.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your guide!

#[doc(hidden)]
pub extern crate core as core_;

use core_::{
cmp::min,
fmt,
ops::{Deref, DerefMut},
};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

#[cfg(feature = "std")]
use std::vec::Vec;

/// Slice pretty print helper
pub struct PrettySlice<'a> (&'a [u8]);
Expand Down