Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/gfx/wr/wrshell/src/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 2 kB image not shown  

Quelle  command.rs

  Sprache: Rust
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


use std::collections::BTreeMap;
use webrender_api::debugger::DebuggerTextureContent;
use crate::net;

// Types for defining debug commands (and queries) that can be run in CLI or GUI mode

pub struct CommandContext<'a> {
    pub net: &'a mut net::HttpConnection,
    args: BTreeMap<String, String>,
}

impl<'a> CommandContext<'a> {
    pub fn new(
        args: BTreeMap<String, String>,
        net: &'a mut net::HttpConnection,
    ) -> Self {
        CommandContext {
            args,
            net,
        }
    }

    #[allow(dead_code)]
    pub fn arg_string(
        &self,
        key: &str,
    ) -> &str {
        self.args[key].as_str()
    }
}

#[derive(Debug)]
pub enum CommandOutput {
    Log(String),
    Err(String),
    TextDocument {
        title: String,
        content: String,
    },
    SerdeDocument {
        kind: String,
        content: String,
    },
    Textures(Vec<DebuggerTextureContent>),
}

pub struct ParamDescriptor {
    pub name: &'static str,
    pub is_required: bool,
}

pub struct CommandDescriptor {
    pub name: &'static str,
    pub alias: Option<&'static str>,
    pub help: &'static str,
    pub params: &'static [ParamDescriptor],
}

impl Default for CommandDescriptor {
    fn default() -> Self {
        CommandDescriptor {
            name: "",
            alias: None,
            help: "",
            params: &[],
        }
    }
}

pub trait Command {
    fn descriptor(&self) -> CommandDescriptor;
    fn run(
        &mut self,
        ctx: &mut CommandContext,
    ) -> CommandOutput;
}

pub struct CommandList {
    commands: Vec<Box<dyn Command>>,
}

impl CommandList {
    pub fn new() -> Self {
        CommandList {
            commands: Vec::new(),
        }
    }

    pub fn register_command(
        &mut self,
        cmd: Box<dyn Command>,
    ) {
        assert!(!cmd.descriptor().name.is_empty(), "Invalid cmd name");
        self.commands.push(cmd);
    }

    pub fn cmds(&self) -> &[Box<dyn Command>] {
        &self.commands
    }

    pub fn get_mut<'a>(&mut self, name: &'a str) -> Option<&mut Box<dyn Command>> {
        self.commands
            .iter_mut()
            .find(|cmd| {
                let desc = cmd.descriptor();
                desc.name == name || desc.alias == Some(name)
            })
    }
}

Messung V0.5 in Prozent
C=90 H=95 G=92

¤ Dauer der Verarbeitung: 0.17 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.