Skip to content

Commit dcf4af9

Browse files
authored
Merge pull request #25 from at-microcosm/nsid-prefix
failing test: panic on unwrap
2 parents 78e47e7 + 379428f commit dcf4af9

File tree

2 files changed

+355
-17
lines changed

2 files changed

+355
-17
lines changed

ufos/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,23 @@ pub enum ConsumerInfo {
277277
},
278278
}
279279

280-
#[derive(Debug, Serialize, JsonSchema)]
280+
#[derive(Debug, PartialEq, Serialize, JsonSchema)]
281281
pub struct NsidCount {
282282
nsid: String,
283283
creates: u64,
284284
// TODO: add updates and deletes
285285
dids_estimate: u64,
286286
}
287287

288-
#[derive(Debug, Serialize, JsonSchema)]
288+
#[derive(Debug, PartialEq, Serialize, JsonSchema)]
289289
pub struct PrefixCount {
290290
prefix: String,
291291
creates: u64,
292292
// TODO: add updates and deletes
293293
dids_estimate: u64,
294294
}
295295

296-
#[derive(Debug, Serialize, JsonSchema)]
296+
#[derive(Debug, PartialEq, Serialize, JsonSchema)]
297297
#[serde(tag = "type", rename_all = "camelCase")]
298298
pub enum PrefixChild {
299299
Collection(NsidCount),
@@ -303,6 +303,7 @@ pub enum PrefixChild {
303303
#[derive(Debug, Serialize, JsonSchema)]
304304
pub struct NsidPrefix(String);
305305
impl NsidPrefix {
306+
/// Input must not include a trailing dot.
306307
pub fn new(pre: &str) -> EncodingResult<Self> {
307308
// it's a valid prefix if appending `.name` makes it a valid NSID
308309
Nsid::new(format!("{pre}.name")).map_err(EncodingError::BadAtriumStringType)?;
@@ -319,9 +320,14 @@ impl NsidPrefix {
319320
);
320321
self.0 == other.domain_authority()
321322
}
323+
/// The prefix as initialized (no trailing dot)
322324
pub fn as_str(&self) -> &str {
323325
self.0.as_str()
324326
}
327+
/// The prefix with a trailing `.` appended to avoid matching a longer segment
328+
pub fn terminated(&self) -> String {
329+
format!("{}.", self.0)
330+
}
325331
}
326332

327333
#[derive(Debug, Serialize, JsonSchema)]

0 commit comments

Comments
 (0)