@@ -19,14 +19,6 @@ use quote::quote;
1919use syn:: { ItemFn , parse_macro_input} ;
2020
2121/// A procedural macro attribute for tracing function calls.
22- /// Usage:
23- /// ```rust
24- /// #[hyperlight_guest_tracing_macro::trace_function]
25- /// fn my_function() {
26- /// // // Function body
27- /// }
28- /// ```
29- ///
3022/// This macro will create a trace record when the function is called
3123///
3224/// The trace record will contain the function name as a string.
@@ -131,78 +123,8 @@ impl syn::parse::Parse for TraceMacroInput {
131123
132124/// This macro creates a trace record with a message, or traces a block with entry/exit records.
133125///
134- /// Usage:
135- /// ```rust
136- /// use hyperlight_guest_tracing_macro::trace;
137- /// trace!("message");
138- /// trace!("message", { /* block of code */ });
139- /// ```
140- ///
141126/// When called with an expression or statement as the second argument, it is wrapped in a block,
142127/// entry and exit trace records are created at the start and end of block, and the result of the block is returned.
143- ///
144- /// # Examples
145- ///
146- /// ## Basic usage: trace with message only
147- ///
148- /// ```
149- /// use hyperlight_guest_tracing_macro::trace;
150- /// trace!("hello");
151- /// ```
152- ///
153- /// ## Trace with a block, returning a value
154- ///
155- /// ```
156- /// use hyperlight_guest_tracing_macro::trace;
157- /// let x = trace!("block", { 42 });
158- /// assert_eq!(x, 42);
159- /// ```
160- ///
161- /// ## Trace with a block using local variables
162- ///
163- /// ```
164- /// use hyperlight_guest_tracing_macro::trace;
165- /// let y = 10;
166- /// let z = trace!("sum", { y + 5 });
167- /// assert_eq!(z, 15);
168- /// ```
169- ///
170- /// ## Trace with a block that returns a reference
171- ///
172- /// ```
173- /// use hyperlight_guest_tracing_macro::trace;
174- /// let s = String::from("abc");
175- /// let r: &str = trace!("ref", { &s });
176- /// assert_eq!(r, "abc");
177- /// ```
178- ///
179- /// ## Control flow: `return` inside the block returns from the function
180- ///
181- /// ```
182- /// use hyperlight_guest_tracing_macro::trace;
183- /// fn foo() -> i32 {
184- /// let _ = trace!("fail", {
185- /// // This return only exits the closure, not the function `foo`.
186- /// return 42;
187- /// });
188- /// assert!(false, "This should not be reached");
189- /// }
190- /// ```
191- ///
192- /// ## Control flow: `break` inside the block exits the outer loop
193- ///
194- /// ```
195- /// use hyperlight_guest_tracing_macro::trace;
196- /// let mut x = 0;
197- /// for i in 1..3 {
198- /// x = i;
199- /// let _ = trace!("msg", {
200- /// // This break should exit the loop.
201- /// break;
202- /// });
203- /// }
204- /// assert_eq!(x, 1, "Loop should break after the first iteration");
205- /// ```
206128#[ proc_macro]
207129pub fn trace ( input : TokenStream ) -> TokenStream {
208130 let parsed = syn:: parse_macro_input!( input as TraceMacroInput ) ;
@@ -251,11 +173,6 @@ pub fn trace(input: TokenStream) -> TokenStream {
251173}
252174
253175/// This macro flushes the trace buffer, sending any remaining trace records to the host.
254- ///
255- /// Usage:
256- /// ```rust
257- /// hyperlight_guest_tracing_macro::flush!();
258- /// ```
259176#[ proc_macro]
260177pub fn flush ( _input : TokenStream ) -> TokenStream {
261178 #[ cfg( feature = "trace" ) ]
0 commit comments