Skip to content

Commit b531051

Browse files
authored
Add new_sample and is_sample to NodeFlags public API. (#238)
1 parent 9cb068f commit b531051

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/flags.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,23 @@ impl From<RawFlags> for IndividualFlags {
251251
}
252252

253253
impl NodeFlags {
254+
/// Create a new flags instance with `IS_SAMPLE` set.
255+
pub fn new_sample() -> Self {
256+
Self::IS_SAMPLE
257+
}
258+
254259
/// We do not enforce valid flags in the library.
255260
/// This function will return `true` if any bits
256261
/// are set that do not correspond to allowed flags.
257262
pub fn is_valid(&self) -> bool {
258263
true
259264
}
265+
266+
/// Returns `true` if flags contains `IS_SAMPLE`,
267+
/// and `false` otherwise.
268+
pub fn is_sample(&self) -> bool {
269+
self.contains(NodeFlags::IS_SAMPLE)
270+
}
260271
}
261272

262273
impl IndividualFlags {
@@ -267,3 +278,20 @@ impl IndividualFlags {
267278
true
268279
}
269280
}
281+
282+
#[cfg(test)]
283+
mod tests {
284+
use super::*;
285+
286+
#[test]
287+
fn node_is_not_sample() {
288+
let n = NodeFlags::default();
289+
assert!(!n.is_sample());
290+
}
291+
292+
#[test]
293+
fn node_is_sample() {
294+
let n = NodeFlags::new_sample();
295+
assert!(n.is_sample());
296+
}
297+
}

0 commit comments

Comments
 (0)