pub struct InstanceId(/* private fields */);Expand description
An arbitrary-precision instance identifier as written by #42.
The Part 21 grammar does not impose a machine-integer bound, so the decimal digits are retained lexically.
Implementations§
Source§impl InstanceId
impl InstanceId
Sourcepub fn new(value: &str) -> Option<Self>
pub fn new(value: &str) -> Option<Self>
Creates an identifier from non-empty ASCII decimal digits.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the decimal digits without the leading #.
Examples found in repository?
examples/recovery_property.rs (line 64)
18fn main() {
19 let base = "ISO-10303-21;\nHEADER;\nFILE_DESCRIPTION((''),'2;1');\n\
20 FILE_NAME('n','t',(''),(''),'p','o','a');\nFILE_SCHEMA(('IFC4'));\nENDSEC;\nDATA;\n\
21 #1= IFCPERSON($,$,'a;b',$,$,$,$,$);\n\
22 #2= IFCPIXELTEXTURE(1,1,8,(\"00AA;BB\"));\n\
23 #3= IFCORGANIZATION($,'o''x',$,$,$); /* c;c */\n\
24 #4= IFCDOOR('real');\nENDSEC;\nEND-ISO-10303-21;\n";
25
26 let mut state = 0x5eed_1234_u64;
27 let mut recovered = 0usize;
28 let mut fabricated = 0usize;
29 let mut span_faults = 0usize;
30
31 for _ in 0..20_000 {
32 let mut bytes = base.as_bytes().to_vec();
33 // Corrupt 1-3 bytes anywhere in the DATA region.
34 let edits = 1 + (lcg(&mut state) % 3) as usize;
35 for _ in 0..edits {
36 let at = 150 + (lcg(&mut state) as usize % (bytes.len() - 150));
37 match lcg(&mut state) % 3 {
38 0 => bytes[at] = b'@',
39 1 => {
40 bytes.remove(at);
41 }
42 _ => bytes[at] = (lcg(&mut state) % 128) as u8,
43 }
44 }
45
46 let Ok(outcome) = parse_with(
47 &bytes,
48 ParseOptions::default().on_malformed_record(OnMalformed::Skip),
49 ) else {
50 continue;
51 };
52 recovered += 1;
53
54 for diagnostic in &outcome.diagnostics {
55 let span = diagnostic.span();
56 if span.start > span.end || span.end > bytes.len() {
57 span_faults += 1;
58 }
59 }
60
61 // Every kept record must appear verbatim in the surviving source: its
62 // `#id=` must exist outside any diagnostic-covered range.
63 for record in &outcome.exchange.data.records {
64 let needle = format!("#{}=", record.id.as_str());
65 let found = String::from_utf8_lossy(&bytes).contains(&needle)
66 || String::from_utf8_lossy(&bytes).contains(&format!("#{} =", record.id.as_str()));
67 if !found {
68 fabricated += 1;
69 eprintln!(
70 "FABRICATED {} in:\n{}",
71 needle,
72 String::from_utf8_lossy(&bytes)
73 );
74 }
75 }
76 }
77
78 println!("recovered={recovered} fabricated={fabricated} span_faults={span_faults}");
79 assert_eq!(fabricated, 0, "recovery invented records");
80 assert_eq!(span_faults, 0, "diagnostic span out of bounds");
81 println!("PROPERTY PROBE OK");
82}Trait Implementations§
Source§impl Clone for InstanceId
impl Clone for InstanceId
Source§fn clone(&self) -> InstanceId
fn clone(&self) -> InstanceId
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InstanceId
impl Debug for InstanceId
Source§impl Display for InstanceId
impl Display for InstanceId
impl Eq for InstanceId
Source§impl From<u64> for InstanceId
impl From<u64> for InstanceId
Source§impl Hash for InstanceId
impl Hash for InstanceId
Source§impl Ord for InstanceId
impl Ord for InstanceId
Source§fn cmp(&self, other: &InstanceId) -> Ordering
fn cmp(&self, other: &InstanceId) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for InstanceId
impl PartialEq for InstanceId
Source§impl PartialOrd for InstanceId
impl PartialOrd for InstanceId
impl StructuralPartialEq for InstanceId
Auto Trait Implementations§
impl Freeze for InstanceId
impl RefUnwindSafe for InstanceId
impl Send for InstanceId
impl Sync for InstanceId
impl Unpin for InstanceId
impl UnsafeUnpin for InstanceId
impl UnwindSafe for InstanceId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more