Comments (2)
Sorry for never replying on this one @greyblake, but it looks like rust-fuzz/arbitrary#33 did get resolved, so I'll go ahead and close this one. If you do still find yourself needing to backport this support though I would be happy to accept a PR for it.
from uuid.
@KodrAus No worries, I know what it is to maintain an open source project.
Right, so I've added that ability to Arbitrary and luckily it was merged.
No we can workaround it with the following:
use uuid:uuid;
use arbitrary::Arbitrary;
#[derive(Arbitrary)]
struct User {
#[arbitrary(with = arbitrary_uuid)]
id: Uuid,
}
pub fn arbitrary_uuid(u: &mut Unstructured<'_>) -> arbitrary::Result<Uuid> {
let bytes: [u8; 16] = u
.bytes(16)?
.try_into()
.map_err(|_| arbitrary::Error::NotEnoughData)?;
Uuid::from_bytes(&bytes).map_err(|_| arbitrary::Error::IncorrectFormat)
}
For the case if, let's say, the uuid
is within a container (Option, Vec, HashMap, etc), one can use arbitrary_ext that helps to deal with that.
For example:
use uuid:uuid;
use arbitrary::Arbitrary;
use arbitrary_ext::{arbitrary_vec, arbitrary_option};
#[derive(Arbitrary)]
struct Group {
#[arbitrary(with = arbitrary_option(arbitrary_uuid))]
admin_id: Option<Uuid>,
#[arbitrary(with = arbitrary_vec(arbitrary_uuid))]
members_ids: Vec<Uuid>,
}
Of course, this can be helpful not only for old versions of UUID crate, but for other crates, which do not support arbitrary as well.
from uuid.
Related Issues (20)
- Add `.as_str()` for Uuid HOT 2
- Simple Encode / Decode HOT 2
- Fix MSRV build
- `Timestamp::from_rfc4122` panics when using timestamp before unix epoch HOT 4
- About UUID v7 implementation HOT 1
- Uuid Serialization & Deserialization Error : expected ident at line 1 column 2 HOT 2
- Optional support for borsh
- Wasm32-unknown-unknown tests not running
- 1.3.4 and 1.3.3 failing in Cloudflare Worker env for different reasons
- Unable to activate feature "v7" HOT 6
- Request: add configuration to enable/disable deserializing different formats HOT 2
- Wrapping behavior of `impl ClockSequence for Context` HOT 4
- Export `error::InvalidUuid` HOT 2
- Make &'a Uuid serializable HOT 3
- UUID no longer supports serde derive attributes HOT 2
- Add bytemuck support HOT 1
- Add `prost::Message` implementation for `Uuid` HOT 3
- v7 should have a counter option? HOT 35
- Macros from 1.5.0 to 1.6.0 break. HOT 4
- Investigate crate size HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uuid.