pub struct RateLimiter { /* private fields */ }Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/sandbox.rs (line 25)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 // Path validation
11 let mut validator = PathValidator::new();
12 validator.add_workspace_folder(std::env::current_dir()?);
13 let safe = validator.validate_path("file:///workspace/src/main.rs")?;
14 println!("Validated path: {}", safe.display());
15
16 // Permissions
17 let perms = ExtensionPermissions::from_manifest(
18 "my-extension".to_string(),
19 Some(vec!["fileSystem.read".to_string()]),
20 )?;
21 perms.check_permission(&Permission::FileSystemRead)?;
22 println!("Permission check passed.");
23
24 // Rate limiting
25 let limiter = RateLimiter::new();
26 limiter.check_rate_limit("my-extension")?;
27 println!("Rate limit check passed.");
28
29 // Secret storage
30 let secrets = SecretStorage::new();
31 secrets.set("my-extension", "api_key", "secret-value")?;
32 let value = secrets.get("my-extension", "api_key")?;
33 println!("Retrieved secret: {}", value.unwrap_or_default());
34
35 Ok(())
36}pub fn with_quota(requests_per_second: u32) -> Self
Sourcepub fn check_rate_limit(&self, extension_id: &str) -> Result<(), String>
pub fn check_rate_limit(&self, extension_id: &str) -> Result<(), String>
Check if a request should be allowed
Examples found in repository?
examples/sandbox.rs (line 26)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 // Path validation
11 let mut validator = PathValidator::new();
12 validator.add_workspace_folder(std::env::current_dir()?);
13 let safe = validator.validate_path("file:///workspace/src/main.rs")?;
14 println!("Validated path: {}", safe.display());
15
16 // Permissions
17 let perms = ExtensionPermissions::from_manifest(
18 "my-extension".to_string(),
19 Some(vec!["fileSystem.read".to_string()]),
20 )?;
21 perms.check_permission(&Permission::FileSystemRead)?;
22 println!("Permission check passed.");
23
24 // Rate limiting
25 let limiter = RateLimiter::new();
26 limiter.check_rate_limit("my-extension")?;
27 println!("Rate limit check passed.");
28
29 // Secret storage
30 let secrets = SecretStorage::new();
31 secrets.set("my-extension", "api_key", "secret-value")?;
32 let value = secrets.get("my-extension", "api_key")?;
33 println!("Retrieved secret: {}", value.unwrap_or_default());
34
35 Ok(())
36}Sourcepub fn remove_limiter(&self, extension_id: &str)
pub fn remove_limiter(&self, extension_id: &str)
Remove rate limiter for an extension (called when extension unloads)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimiter
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin for RateLimiter
impl UnwindSafe for RateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more