-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lifetimes to nt types and add nt macro
- Loading branch information
1 parent
f47407d
commit b7001e6
Showing
3 changed files
with
64 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::sync::OnceLock; | ||
|
||
use crate::{payloads::Payload, Instance, NT_Now, NT_Publisher}; | ||
|
||
#[macro_export] | ||
macro_rules! nt { | ||
($topic_name:literal, $value:expr) => {{ | ||
static PUBLISHER: ::std::sync::OnceLock<$crate::bindings::NT_Publisher> = | ||
::std::sync::OnceLock::new(); | ||
|
||
$crate::macros::_internal_set(&PUBLISHER, $topic_name, $value); | ||
}}; | ||
} | ||
|
||
pub fn _internal_set<T: Payload>( | ||
handle: &'static OnceLock<NT_Publisher>, | ||
topic_name: &str, | ||
value: T, | ||
) { | ||
value.to_entry( | ||
*handle.get_or_init(|| { | ||
let publisher = Instance::default_instance() | ||
.topic(topic_name) | ||
.publish::<T>(Default::default()); | ||
|
||
let handle = publisher.handle; | ||
|
||
std::mem::forget(publisher); | ||
|
||
handle | ||
}), | ||
unsafe { NT_Now() }, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters