Skip to content

Commit c5dabdb

Browse files
committed
Simplify methods
1 parent b796f80 commit c5dabdb

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

rust/otel-arrow-rust/src/pdata/mod.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ pub mod otlp;
2323
#[derive(Clone, Copy, Debug)]
2424
pub struct TraceID([u8; 16]);
2525

26-
type Error = &'static str;
27-
28-
impl<'a> TraceID {
29-
pub fn try_new(value: &[u8]) -> Result<TraceID, Error> {
30-
if value.len() == 16 {
31-
Ok(TraceID(value.try_into().unwrap()))
32-
} else {
33-
Err("wrong size [u8] for TraceID")
34-
}
26+
impl TraceID {
27+
pub fn new(value: &[u8; 16]) -> TraceID {
28+
TraceID(*value)
3529
}
3630
}
3731

@@ -50,12 +44,8 @@ impl Into<Vec<u8>> for SpanID {
5044
}
5145
}
5246

53-
impl<'a> SpanID {
54-
pub fn try_new(value: &[u8]) -> Result<SpanID, Error> {
55-
if value.len() == 8 {
56-
Ok(SpanID(value.try_into().unwrap()))
57-
} else {
58-
Err("wrong size [u8] for SpanID")
59-
}
47+
impl SpanID {
48+
pub fn new(value: &[u8; 8]) -> SpanID{
49+
SpanID(*value)
6050
}
6151
}

rust/otel-arrow-rust/src/validation/testdata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub mod traces {
1818
let start_time = 1619712000000000000u64;
1919
let end_time = 1619712001000000000u64;
2020
let trace_id =
21-
TraceID::try_new(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]).unwrap();
22-
let span_id = SpanID::try_new(&[1, 2, 3, 4, 5, 6, 7, 8]).unwrap();
21+
TraceID::new(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
22+
let span_id = SpanID::new(&[1, 2, 3, 4, 5, 6, 7, 8]);
2323

2424
let span = Span::build(trace_id, span_id, "test_span", start_time)
2525
.end_time_unix_nano(end_time)

0 commit comments

Comments
 (0)