pub struct FunctionServer { /* private fields */ }Expand description
Unified server for hosting serverless functions.
§Examples
use serverless_fn::server::{FunctionServer, ServerConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Method 1: Using builder pattern
FunctionServer::new()
.host("0.0.0.0")
.port(3000)
.start()
.await?;
// Method 2: Using custom config
let config = ServerConfig::new().host("0.0.0.0").port(3000);
FunctionServer::with_config(config)
.start()
.await?;
Ok(())
}Implementations§
Source§impl FunctionServer
impl FunctionServer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new server with default configuration.
Examples found in repository?
examples/usage_example.rs (line 91)
83async fn run_server() -> Result<(), ServerlessError> {
84 println!("Starting serverless function server...");
85 let host = "0.0.0.0";
86 let port = 3000;
87 println!("Server listening on http://{}:{}", host, port);
88
89 // Start the server - all functions marked with #[serverless] are automatically registered
90 // via the inventory crate
91 Server::new()
92 .host(host)
93 .port(port)
94 .start()
95 .await
96 .map_err(|e| ServerlessError::RemoteExecution(e.to_string()))?;
97
98 Ok(())
99}Sourcepub fn with_config(config: ServerConfig) -> Self
pub fn with_config(config: ServerConfig) -> Self
Creates a new server with custom configuration.
Sourcepub fn host(self, host: &str) -> Self
pub fn host(self, host: &str) -> Self
Sets the host address to bind to.
Examples found in repository?
examples/usage_example.rs (line 92)
83async fn run_server() -> Result<(), ServerlessError> {
84 println!("Starting serverless function server...");
85 let host = "0.0.0.0";
86 let port = 3000;
87 println!("Server listening on http://{}:{}", host, port);
88
89 // Start the server - all functions marked with #[serverless] are automatically registered
90 // via the inventory crate
91 Server::new()
92 .host(host)
93 .port(port)
94 .start()
95 .await
96 .map_err(|e| ServerlessError::RemoteExecution(e.to_string()))?;
97
98 Ok(())
99}Sourcepub fn port(self, port: u16) -> Self
pub fn port(self, port: u16) -> Self
Sets the port to listen on.
Examples found in repository?
examples/usage_example.rs (line 93)
83async fn run_server() -> Result<(), ServerlessError> {
84 println!("Starting serverless function server...");
85 let host = "0.0.0.0";
86 let port = 3000;
87 println!("Server listening on http://{}:{}", host, port);
88
89 // Start the server - all functions marked with #[serverless] are automatically registered
90 // via the inventory crate
91 Server::new()
92 .host(host)
93 .port(port)
94 .start()
95 .await
96 .map_err(|e| ServerlessError::RemoteExecution(e.to_string()))?;
97
98 Ok(())
99}Sourcepub fn config(&self) -> &ServerConfig
pub fn config(&self) -> &ServerConfig
Returns a reference to the server configuration.
Sourcepub fn register_http_route<F, T>(&mut self, path: &str, handler: F)
pub fn register_http_route<F, T>(&mut self, path: &str, handler: F)
Registers a function for HTTP transport.
Sourcepub async fn start(self) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn start(self) -> Result<(), Box<dyn Error + Send + Sync>>
Starts the server and listens for incoming requests.
Automatically discovers and registers all serverless functions using the inventory crate.
§Errors
Returns an error if the server fails to start.
Examples found in repository?
examples/usage_example.rs (line 94)
83async fn run_server() -> Result<(), ServerlessError> {
84 println!("Starting serverless function server...");
85 let host = "0.0.0.0";
86 let port = 3000;
87 println!("Server listening on http://{}:{}", host, port);
88
89 // Start the server - all functions marked with #[serverless] are automatically registered
90 // via the inventory crate
91 Server::new()
92 .host(host)
93 .port(port)
94 .start()
95 .await
96 .map_err(|e| ServerlessError::RemoteExecution(e.to_string()))?;
97
98 Ok(())
99}Trait Implementations§
Auto Trait Implementations§
impl Freeze for FunctionServer
impl !RefUnwindSafe for FunctionServer
impl Send for FunctionServer
impl Sync for FunctionServer
impl Unpin for FunctionServer
impl UnsafeUnpin for FunctionServer
impl !UnwindSafe for FunctionServer
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