#[cfg(feature = "std")]
use std::collections::HashMap;
#[cfg(not(feature = "std"))]
use alloc::collections::BTreeMap as HashMap;
#[cfg(not(feature = "std"))]
use alloc::string::{String, ToString};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExtensionState {
Uninitialized,
Initializing,
Active,
Paused,
Error,
ShuttingDown,
Shutdown,
}
impl ExtensionState {
pub fn is_active(&self) -> bool {
matches!(self, Self::Active)
}
pub fn is_usable(&self) -> bool {
matches!(self, Self::Active | Self::Paused)
}
pub fn is_error(&self) -> bool {
matches!(self, Self::Error)
}
}
#[derive(Debug, Clone)]
pub struct ExtensionCommand {
pub id: String,
pub name: String,
pub description: String,
pub shortcut: Option<String>,
pub category: String,
pub requires_document: bool,
}
impl ExtensionCommand {
pub fn new(id: String, name: String, description: String) -> Self {
Self {
id,
name,
description,
shortcut: None,
category: "General".to_string(),
requires_document: true,
}
}
pub fn with_shortcut(mut self, shortcut: String) -> Self {
self.shortcut = Some(shortcut);
self
}
pub fn with_category(mut self, category: String) -> Self {
self.category = category;
self
}
pub fn requires_document(mut self, requires: bool) -> Self {
self.requires_document = requires;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MessageLevel {
Info,
Warning,
Error,
Success,
}
#[derive(Debug, Clone)]
pub struct ExtensionResult {
pub success: bool,
pub message: Option<String>,
pub data: HashMap<String, String>,
}
impl ExtensionResult {
pub fn success() -> Self {
Self {
success: true,
message: None,
data: HashMap::new(),
}
}
pub fn success_with_message(message: String) -> Self {
Self {
success: true,
message: Some(message),
data: HashMap::new(),
}
}
pub fn failure(message: String) -> Self {
Self {
success: false,
message: Some(message),
data: HashMap::new(),
}
}
pub fn with_data(mut self, key: String, value: String) -> Self {
self.data.insert(key, value);
self
}
}