Skip to content

Commit

Permalink
Add short example to Nucleo
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrutar committed Dec 13, 2024
1 parent f350b3d commit d9d707d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,35 @@ impl State {

/// A high level matcher worker that quickly computes matches in a background
/// threadpool.
///
/// ## Example
/// ```
/// use std::sync::atomic::{AtomicBool, Ordering};
/// use std::sync::Arc;
/// use std::thread;
///
/// use nucleo::{Config, Nucleo};
///
/// static NEEDS_UPDATE: AtomicBool = AtomicBool::new(false);
///
/// // initialize a new matcher with default configuration and one column
/// let matcher = Nucleo::new(
/// Config::DEFAULT,
/// Arc::new(|| NEEDS_UPDATE.store(true, Ordering::Relaxed)),
/// None,
/// 1
/// );
///
/// // get a handle to add items to the matcher
/// let injector = matcher.injector();
///
/// // add items to the matcher
/// thread::spawn(move || {
/// injector.push("Hello, world!".to_string(), |s, cols| {
/// cols[0] = (&**s).into();
/// });
/// });
/// ```
pub struct Nucleo<T: Sync + Send + 'static> {
// the way the API is build we totally don't actually need these to be Arcs
// but this lets us avoid some unsafe
Expand Down

0 comments on commit d9d707d

Please sign in to comment.