1 unstable release

new 0.1.0 Jan 17, 2025

#286 in Unix APIs

Download history 87/week @ 2025-01-12

87 downloads per month

MIT license

23KB
390 lines

x11docker-rs

The X11docker library is a Rust wrapper for the x11docker script. It allows you to build arguments, spawn X11docker commands, and terminate the running child processes conveniently.

Features

  • Define and configure X11docker arguments with the builder pattern.
  • Spawn an X11docker process with specified arguments.
  • Terminate a running X11docker process safely.

Requirements

  • x11docker needs to be installed on your system to run the exec() method.
  • Unix-based environment (as the library currently uses Unix-specific process management via libc).

Usage Example

Below is an example of how to use the X11docker library in your project.

Adding the Dependency

Add the following to your Cargo.toml file to use X11docker:

[dependencies]
x11docker = "0.1.0"

Example Code

use x11docker::X11docker;
use std::collections::HashSet;

fn main() {
    // Create a new instance of X11docker
    let mut x11docker = X11docker::default()
        .internet()
        .image_name("my_docker_image")
        .container_name("my_container")
        .use_xpra();

    // Execute the x11docker command
    match x11docker.exec() {
        Ok(_) => println!("X11docker started successfully!"),
        Err(e) => eprintln!("Failed to start x11docker container: {e}"),
    }

    // Perform operations...

    // Terminate the running child process
    if let Err(e) = x11docker.terminate() {
        eprintln!("Failed to terminate the process: {e}");
    }
}

Structs and Methods

X11docker

The main struct of the library used to configure and manage X11docker processes.

  • arguments: Method to set arguments explicitly.
  • internet: Adds the Internet option, allowing internet access in the container.
  • image_name(name: &str): Adds the specified image name to the arguments.
  • container_name(name: &str): Adds the specified container name to the arguments.
  • use_xpra(): Adds the Xpra option to use Xpra for X11 forwarding.
  • exec(): Executes the X11docker command with the configured arguments.
  • terminate(): Terminates the running X11docker child process.

X11dockerOption

Enum that defines different options available for X11docker.

  • Internet: Enables internet access for the container.
  • ImageName(String): Specifies the Docker image name.
  • ContainerName(String): Specifies the container name.
  • Xpra: Enables Xpra for remote GUI access.

Notes

  • The exec() function requires that the x11docker script be available in your system's PATH. Otherwise, it will return an error.
  • The terminate() method uses Unix signals to kill the child process, making it incompatible with non-Unix platforms.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contribution

Contributions are welcome! Feel free to open issues or submit pull requests.

Dependencies

~43KB