Struct x11rb::resource_manager::Database

source ·
pub struct Database {
    entries: Vec<Entry>,
}
Expand description

A X11 resource database.

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

Fields§

§entries: Vec<Entry>

Implementations§

source§

impl Database

source

pub const GET_RESOURCE_DATABASE: GetPropertyRequest = _

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.

source

pub fn new_from_default( reply: &GetPropertyReply, hostname: OsString, ) -> Database

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().

source

pub fn new_from_get_property_reply(reply: &GetPropertyReply) -> Option<Database>

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.

source

pub fn new_from_data(data: &[u8]) -> Database

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.

source

pub fn new_from_data_with_base_directory( data: &[u8], base_path: impl AsRef<Path>, ) -> Database

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.

source

pub fn get_bytes( &self, resource_name: &str, resource_class: &str, ) -> Option<&[u8]>

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")
}
source

pub fn get_string( &self, resource_name: &str, resource_class: &str, ) -> Option<&str>

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")
}
source

pub fn get_bool( &self, resource_name: &str, resource_class: &str, ) -> Option<bool>

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)
}
source

pub fn get_value<T>( &self, resource_name: &str, resource_class: &str, ) -> Result<Option<T>, <T as FromStr>::Err>
where T: FromStr,

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§

source§

impl Clone for Database

source§

fn clone(&self) -> Database

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Database

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Database

source§

fn default() -> Database

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.