| Crates.io | pastiche |
| lib.rs | pastiche |
| version | 0.2.0 |
| created_at | 2024-11-13 16:49:24.838989+00 |
| updated_at | 2024-11-19 20:25:31.253326+00 |
| description | A library for exposing non public types, fields, and functions from a crate |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1446803 |
| size | 51,221 |
A library for exposing non public types, fields, and functions from a crate.
The libraries I use often expose most of their lower level details but forget
to mark a few structs or fields as public. Necessitating me to copy over the
struct, a load of traits, all the methods I need, everything those traits
and methods need to import, and all the crates they use. Just for me to be able
to add "pub" in front of it.
Most functionality is implemented but this is mainly meant for testing or debugging and is still a work in progress. So don't use this for production code.
const, enum, fn, macro_rules, static, struct, trait, unionStruct, fn, etc)use pastiche::pastiche_attr;
use std::num::IntErrorKind;
use std::str::FromStr;
/// A new type that shadows the definition and attributes at
/// [`core::num::ParseIntError`].
/// Internally it searches the fs and copy-pastes the definition.
#[pastiche_attr]
#[pastiche_crate = "stable@1.82.0"]
// NOTE: doesn't support re-exports rn, so we have to specify the
// "real" module path
#[pastiche_path = "core::num::error::ParseIntError"]
#[pastiche_sub_vis(pub)] // set fields to public
pub struct MyParseIntError {
// body is ignored for now
}
fn main() {
// We can now directly construct a ParseIntError.
let my_error = MyParseIntError { kind: IntErrorKind::InvalidDigit };
dbg!(&my_error);
// Rather than having to fail a parse. :/
let std_error = i32::from_str("baddbeef").unwrap_err();
dbg!(&std_error);
assert_eq!(&my_error.kind, std_error.kind());
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.