Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit439e029

Browse files
authored
Merge pull request#76 from poeschel/canctrlmodes_has_mode
Add CanCtrlModes::has_mode(mode: CanCtrlMode)
2 parents6187c98 +5b03ee6 commit439e029

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎src/nl/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,29 @@ impl CanCtrlModes {
334334
pubfnclear(&mutself){
335335
self.0 = can_ctrlmode::default();
336336
}
337+
338+
/// Test if this CanCtrlModes has a specific `mode` turned on
339+
///
340+
/// This can be useful for inspecting an [InterfaceCanParams] obtained from
341+
/// [CanInterface::details].
342+
///
343+
/// # Examples
344+
///
345+
/// ```
346+
/// use socketcan::nl::CanCtrlModes;
347+
/// use socketcan::CanCtrlMode;
348+
///
349+
/// let modes = CanCtrlModes::new(0x20, 0x20); // This is bit 5 (CanCtrlMode::Fd)
350+
/// assert_eq!(modes.has_mode(CanCtrlMode::Fd), true);
351+
/// assert_eq!(modes.has_mode(CanCtrlMode::ListenOnly), false);
352+
/// ```
353+
pubfnhas_mode(&self,mode:CanCtrlMode) ->bool{
354+
if(mode.mask()&self.0.flags) !=0{
355+
returntrue;
356+
}
357+
358+
false
359+
}
337360
}
338361

339362
implFrom<can_ctrlmode>forCanCtrlModes{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp