pub struct Database { /* private fields */ }
Expand description

A X11 resource database.

The recommended way to load a database is through Database::new_from_default.

Implementations

The GetPropertyRequest to load the X11 resource database from the root window.

Copy this struct, set its window field to the root window of the first screen send the resulting request to the X11 server. The reply can be passed to Self::new_from_default.

Create a new X11 resource database from the default locations.

The reply argument should come from Self::GET_RESOURCE_DATABASE with its window field set to the window ID of the first root window. The hostname argument should be the hostname of the running system.

The default location is a combination of two places. First, the following places are searched for data:

The result of the above search of the above search is combined with:

  • The contents of the file $XENVIRONMENT, if this environment variable is set.
  • Otherwise, the contents of $HOME/.Xdefaults-[hostname].

This function only returns an error if communication with the X11 server fails. All other errors are ignored. It might be that an empty database is returned.

The behaviour of this function is mostly equivalent to Xlib’s XGetDefault(). The exception is that XGetDefault() does not load $HOME/.Xresources.

The behaviour of this function is equivalent to xcb-util-xrm’s xcb_xrm_database_from_default().

Construct a new X11 resource database from a GetPropertyReply.

The reply should come from Self::GET_RESOURCE_DATABASE with its window field set to the window ID of the first root window.

Construct a new X11 resource database from raw data.

This function parses data like Some.Entry: Value\n#include "some_file"\n and returns the resulting resource database. Parsing cannot fail since unparsable lines are simply ignored.

See Self::new_from_data_with_base_directory for a version that allows to provide a path that is used for resolving relative #include statements.

Construct a new X11 resource database from raw data.

This function parses data like Some.Entry: Value\n#include "some_file"\n and returns the resulting resource database. Parsing cannot fail since unparsable lines are simply ignored.

When a relative #include statement is encountered, the file to include is searched relative to the given base_path.

Get a value from the resource database as a byte slice.

The given values describe a query to the resource database. resource_class can be an empty string, but otherwise must contain the same number of components as resource_name. Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.

For example, this is how Xterm could query one of its settings if it where written in Rust (see man xterm):

use x11rb_protocol::resource_manager::Database;
fn get_pointer_shape(db: &Database) -> &[u8] {
    db.get_bytes("XTerm.vt100.pointerShape", "XTerm.VT100.Cursor").unwrap_or(b"xterm")
}

Get a value from the resource database as a byte slice.

The given values describe a query to the resource database. resource_class can be an empty string, but otherwise must contain the same number of components as resource_name. Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.

If an entry is found that is not a valid utf8 str, None is returned.

For example, this is how Xterm could query one of its settings if it where written in Rust (see man xterm):

use x11rb_protocol::resource_manager::Database;
fn get_pointer_shape(db: &Database) -> &str {
    db.get_string("XTerm.vt100.pointerShape", "XTerm.VT100.Cursor").unwrap_or("xterm")
}

Get a value from the resource database as a byte slice.

The given values describe a query to the resource database. resource_class can be an empty string, but otherwise must contain the same number of components as resource_name. Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.

This function interprets “true”, “on”, “yes” as true-ish and “false”, “off”, “no” als false-ish. Numbers are parsed and are true if they are not zero. Unknown values are mapped to None.

For example, this is how Xterm could query one of its settings if it where written in Rust (see man xterm):

use x11rb_protocol::resource_manager::Database;
fn get_bell_is_urgent(db: &Database) -> bool {
    db.get_bool("XTerm.vt100.bellIsUrgent", "XTerm.VT100.BellIsUrgent").unwrap_or(false)
}

Get a value from the resource database and parse it.

The given values describe a query to the resource database. resource_class can be an empty string, but otherwise must contain the same number of components as resource_name. Both strings may only contain alphanumeric characters or ‘-’, ‘_’, and ‘.’.

If no value is found, Ok(None) is returned. Otherwise, the result from [FromStr::from_str] is returned with Ok(value) replaced with Ok(Some(value)).

For example, this is how Xterm could query one of its settings if it where written in Rust (see man xterm):

use x11rb_protocol::resource_manager::Database;
fn get_print_attributes(db: &Database) -> u8 {
    db.get_value("XTerm.vt100.printAttributes", "XTerm.VT100.PrintAttributes")
            .ok().flatten().unwrap_or(1)
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more