Struct watchman_client::Client[][src]

pub struct Client { /* fields omitted */ }
Expand description

A live connection to a watchman server. Use Connector to establish a connection.

Implementations

This is typically the first method invoked on a client. Its purpose is to ensure that the watchman server is watching the specified path and to resolve it to a ResolvedRoot instance.

The path to resolve must be a canonical path; watchman performs strict name resolution to detect TOCTOU issues and will generate an error if the path is not the canonical name.

Note that for regular filesystem watches, if the requested path is not yet being watched, this method will not yield until the watchman server has completed a recursive crawl of that portion of the filesystem. In other words, the worst case performance of this is O(recursive-number-of-files) and is impacted by the underlying storage device and its performance characteristics.

Perform a generic watchman query. The F type is a struct defined by the query_result_type! macro, or, if you want only the file name from the results, the NameOnly struct.

use watchman_client::prelude::*;
use serde::Deserialize;

query_result_type! {
    struct NameAndType {
        name: NameField,
        file_type: FileTypeField,
    }
}

async fn query(
   client: &mut Client,
   resolved: &ResolvedRoot
) -> Result<(), Box<dyn std::error::Error>> {
   let response: QueryResult<NameAndType> = client
       .query(
           &resolved,
              QueryRequestCommon {
               glob: Some(vec!["**/*.rs".to_string()]),
               ..Default::default()
           },
       )
       .await?;
   println!("response: {:#?}", response);
   Ok(())
}

When constructing your result type, you can select from the following fields:

(See the fields module for a definitive list)

The file names are all relative to the root parameter.

Create a Subscription that will yield file changes as they occur in real time. The F type is a struct defined by the query_result_type! macro, or, if you want only the file name from the results, the NameOnly struct.

Returns two pieces of information:

  • A Subscription handle that can be used to yield changes as they are observed by watchman
  • A SubscribeResponse that contains some data about the state of the watch at the time the subscription was initiated

Expand a set of globs into the set of matching file names. The globs must be relative to the root parameter. The returned file names are all relative to the root parameter.

Returns the current clock value for a watched root. If sync_timeout is SyncTimeout::DisableCookie then the instantaneous clock value is returned without using a sync cookie.

Otherwise, a sync cookie will be created and the server will wait for up to the associated sync_timeout duration to observe it. If that timeout is reached, this method will yield an error.

When should you use a cookie? If you need to a clock value that is guaranteed to reflect any filesystem changes that happened before a given point in time you should use a sync cookie.

See also:

Returns the current configuration for a watched root.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.