Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "restate-sdk"
version = "0.7.0"
edition = "2021"
edition = "2024"
description = "Restate SDK for Rust"
license = "MIT"
repository = "https://github.com/restatedev/sdk-rust"
rust-version = "1.76.0"
rust-version = "1.85.0"

[[example]]
name = "tracing"
Expand Down
2 changes: 1 addition & 1 deletion examples/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use restate_sdk::prelude::*;
use std::time::Duration;
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer};
use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt};

#[restate_sdk::service]
trait Greeter {
Expand Down
3 changes: 2 additions & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "restate-sdk-macros"
version = "0.7.0"
edition = "2021"
edition = "2024"
description = "Restate SDK for Rust macros"
license = "MIT"
repository = "https://github.com/restatedev/sdk-rust"
rust-version = "1.85.0"

[lib]
proc-macro = true
Expand Down
16 changes: 9 additions & 7 deletions macros/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use syn::parse::{Parse, ParseStream};
use syn::spanned::Spanned;
use syn::token::Comma;
use syn::{
braced, parenthesized, parse_quote, Attribute, Error, Expr, ExprLit, FnArg, GenericArgument,
Ident, Lit, Pat, PatType, Path, PathArguments, Result, ReturnType, Token, Type, Visibility,
Attribute, Error, Expr, ExprLit, FnArg, GenericArgument, Ident, Lit, Pat, PatType, Path,
PathArguments, Result, ReturnType, Token, Type, Visibility, braced, parenthesized, parse_quote,
};

/// Accumulates multiple errors into a result.
Expand Down Expand Up @@ -194,10 +194,12 @@ impl Parse for Handler {
input.parse::<Token![;]>()?;

let (ok_ty, err_ty) = match &return_type {
ReturnType::Default => return Err(Error::new(
return_type.span(),
"The return type cannot be empty, only Result or restate_sdk::prelude::HandlerResult is supported as return type",
)),
ReturnType::Default => {
return Err(Error::new(
return_type.span(),
"The return type cannot be empty, only Result or restate_sdk::prelude::HandlerResult is supported as return type",
));
}
ReturnType::Type(_, ty) => {
if let Some((ok_ty, err_ty)) = extract_handler_result_parameter(ty) {
(ok_ty, err_ty)
Expand Down Expand Up @@ -251,7 +253,7 @@ fn read_literal_attribute_name(attr: &Attribute) -> Result<Option<String>> {
.filter(|val| val.path.require_ident().is_ok_and(|i| i == "name"))
.map(|val| {
if let Expr::Lit(ExprLit {
lit: Lit::Str(ref literal),
lit: Lit::Str(literal),
..
}) = &val.value
{
Expand Down
4 changes: 2 additions & 2 deletions macros/src/gen.rs → macros/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ast::{Handler, Object, Service, ServiceInner, ServiceType, Workflow};
use proc_macro2::TokenStream as TokenStream2;
use proc_macro2::{Ident, Literal};
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use syn::{Attribute, PatType, Visibility};

pub(crate) struct ServiceGenerator<'a> {
Expand Down Expand Up @@ -386,7 +386,7 @@ impl<'a> ServiceGenerator<'a> {
}
}

impl<'a> ToTokens for ServiceGenerator<'a> {
impl ToTokens for ServiceGenerator<'_> {
fn to_tokens(&self, output: &mut TokenStream2) {
output.extend(vec![
self.trait_service(),
Expand Down
4 changes: 2 additions & 2 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
extern crate proc_macro;

mod ast;
mod gen;
mod generator;

use crate::ast::{Object, Service, Workflow};
use crate::gen::ServiceGenerator;
use crate::generator::ServiceGenerator;
use proc_macro::TokenStream;
use quote::ToTokens;
use syn::parse_macro_input;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.82.0"
channel = "1.85.0"
profile = "minimal"
components = ["rustfmt", "clippy"]
20 changes: 10 additions & 10 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct Context<'ctx> {
inner: &'ctx ContextInternal,
}

impl<'ctx> Context<'ctx> {
impl Context<'_> {
/// Get request headers.
pub fn headers(&self) -> &HeaderMap {
&self.headers
Expand Down Expand Up @@ -60,7 +60,7 @@ pub struct SharedObjectContext<'ctx> {
pub(crate) inner: &'ctx ContextInternal,
}

impl<'ctx> SharedObjectContext<'ctx> {
impl SharedObjectContext<'_> {
/// Get object key.
pub fn key(&self) -> &str {
&self.key
Expand Down Expand Up @@ -100,7 +100,7 @@ pub struct ObjectContext<'ctx> {
pub(crate) inner: &'ctx ContextInternal,
}

impl<'ctx> ObjectContext<'ctx> {
impl ObjectContext<'_> {
/// Get object key.
pub fn key(&self) -> &str {
&self.key
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<'ctx> From<(&'ctx ContextInternal, InputMetadata)> for SharedWorkflowContex
}
}

impl<'ctx> SharedWorkflowContext<'ctx> {
impl SharedWorkflowContext<'_> {
/// Get workflow key.
pub fn key(&self) -> &str {
&self.key
Expand Down Expand Up @@ -193,7 +193,7 @@ impl<'ctx> From<(&'ctx ContextInternal, InputMetadata)> for WorkflowContext<'ctx
}
}

impl<'ctx> WorkflowContext<'ctx> {
impl WorkflowContext<'_> {
/// Get workflow key.
pub fn key(&self) -> &str {
&self.key
Expand Down Expand Up @@ -752,7 +752,7 @@ pub trait ContextSideEffects<'ctx>: private::SealedContext<'ctx> {
/// # use restate_sdk::prelude::*;
/// # use rand::Rng;
/// async fn rand_generate(mut ctx: Context<'_>) {
/// let x: u32 = ctx.rand().gen();
/// let x: u32 = ctx.rand().random();
/// # }
/// ```
///
Expand Down Expand Up @@ -832,13 +832,13 @@ pub trait ContextReadState<'ctx>: private::SealedContext<'ctx> {
/// Get state
fn get<T: Deserialize + 'static>(
&self,
key: &str,
key: &'ctx str,
) -> impl Future<Output = Result<Option<T>, TerminalError>> + 'ctx {
self.inner_context().get(key)
}

/// Get state keys
fn get_keys(&self) -> impl Future<Output = Result<Vec<String>, TerminalError>> + 'ctx {
fn get_keys(&'ctx self) -> impl Future<Output = Result<Vec<String>, TerminalError>> + 'ctx {
self.inner_context().get_keys()
}
}
Expand Down Expand Up @@ -923,15 +923,15 @@ pub trait ContextPromises<'ctx>: private::SealedContext<'ctx> {
/// Create a promise
fn promise<T: Deserialize + 'static>(
&'ctx self,
key: &str,
key: &'ctx str,
) -> impl DurableFuture<Output = Result<T, TerminalError>> + 'ctx {
self.inner_context().promise(key)
}

/// Peek a promise
fn peek_promise<T: Deserialize + 'static>(
&self,
key: &str,
key: &'ctx str,
) -> impl Future<Output = Result<Option<T>, TerminalError>> + 'ctx {
self.inner_context().peek_promise(key)
}
Expand Down
3 changes: 2 additions & 1 deletion src/context/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ macro_rules! select {
let handles = vec![$(
$crate::count_field!(futures_init.$($skip)*).handle()
,)+];
let select_fut = futures_init.0.inner_context().select(handles);
let inner_context = futures_init.0.inner_context();
let select_fut = inner_context.select(handles);

match select_fut.await {
$(
Expand Down
6 changes: 3 additions & 3 deletions src/endpoint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ use futures::{FutureExt, TryFutureExt};
use pin_project_lite::pin_project;
use restate_sdk_shared_core::{
CoreVM, DoProgressResponse, Error as CoreError, Header, NonEmptyValue, NotificationHandle,
RetryPolicy, RunExitResult, TakeOutputResult, Target, TerminalFailure, Value, VM,
RetryPolicy, RunExitResult, TakeOutputResult, Target, TerminalFailure, VM, Value,
};
use std::borrow::Cow;
use std::collections::HashMap;
use std::future::{ready, Future};
use std::future::{Future, ready};
use std::marker::PhantomData;
use std::mem;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{ready, Context, Poll};
use std::task::{Context, Poll, ready};
use std::time::{Duration, Instant, SystemTime};

pub struct ContextInternalInner {
Expand Down
8 changes: 4 additions & 4 deletions src/endpoint/futures/async_result_poll.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::endpoint::context::ContextInternalInner;
use crate::endpoint::ErrorInner;
use crate::endpoint::context::ContextInternalInner;
use restate_sdk_shared_core::{
DoProgressResponse, Error as CoreError, NotificationHandle, TakeOutputResult, TerminalFailure,
Value, VM,
VM, Value,
};
use std::future::Future;
use std::pin::Pin;
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Future for VmAsyncResultPollFuture {
}
}
TakeOutputResult::EOF => {
return Poll::Ready(Err(ErrorInner::UnexpectedOutputClosed))
return Poll::Ready(Err(ErrorInner::UnexpectedOutputClosed));
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ impl Future for VmAsyncResultPollFuture {
return Poll::Ready(Ok(Value::Failure(TerminalFailure {
code: 409,
message: "cancelled".to_string(),
})))
})));
}
Err(e) => {
return Poll::Ready(Err(e.into()));
Expand Down
2 changes: 1 addition & 1 deletion src/endpoint/futures/durable_future_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pin_project_lite::pin_project;
use restate_sdk_shared_core::NotificationHandle;
use std::future::Future;
use std::pin::Pin;
use std::task::{ready, Context, Poll};
use std::task::{Context, Poll, ready};

pin_project! {
/// Future that intercepts errors of inner future, and passes them to ContextInternal
Expand Down
4 changes: 3 additions & 1 deletion src/endpoint/futures/handler_state_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ where
Poll::Pending => Poll::Pending,
},
Err(oneshot::error::TryRecvError::Closed) => {
panic!("This is unexpected, this future is still being polled although the sender side was dropped. This should not be possible, because the sender is dropped when this future returns Poll:ready().")
panic!(
"This is unexpected, this future is still being polled although the sender side was dropped. This should not be possible, because the sender is dropped when this future returns Poll:ready()."
)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/endpoint/futures/intercept_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::errors::TerminalError;
use pin_project_lite::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::task::{ready, Context, Poll};
use std::task::{Context, Poll, ready};

pin_project! {
/// Future that intercepts errors of inner future, and passes them to ContextInternal
Expand Down
6 changes: 3 additions & 3 deletions src/endpoint/futures/select_poll.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::endpoint::context::ContextInternalInner;
use crate::endpoint::ErrorInner;
use crate::endpoint::context::ContextInternalInner;
use crate::errors::TerminalError;
use restate_sdk_shared_core::{
DoProgressResponse, Error as CoreError, NotificationHandle, TakeOutputResult, TerminalFailure,
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Future for VmSelectAsyncResultPollFuture {
}
}
TakeOutputResult::EOF => {
return Poll::Ready(Err(ErrorInner::UnexpectedOutputClosed))
return Poll::Ready(Err(ErrorInner::UnexpectedOutputClosed));
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ impl Future for VmSelectAsyncResultPollFuture {
code: 409,
message: "cancelled".to_string(),
}
.into())))
.into())));
}
Err(e) => {
return Poll::Ready(Err(e.into()));
Expand Down
16 changes: 10 additions & 6 deletions src/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ use http_body::{Body, Frame, SizeHint};
use http_body_util::{BodyExt, Either, Full};
use pin_project_lite::pin_project;
use restate_sdk_shared_core::{
CoreVM, Error as CoreError, Header, HeaderMap, IdentityVerifier, ResponseHead, VerifyError, VM,
CoreVM, Error as CoreError, Header, HeaderMap, IdentityVerifier, ResponseHead, VM, VerifyError,
};
use std::collections::HashMap;
use std::convert::Infallible;
use std::future::poll_fn;
use std::ops::Deref;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{ready, Context, Poll};
use std::task::{Context, Poll, ready};
use tokio::sync::mpsc;
use tracing::{info_span, warn, Instrument};
use tracing::{Instrument, info_span, warn};

#[allow(clippy::declare_interior_mutable_const)]
const X_RESTATE_SERVER: HeaderName = HeaderName::from_static("x-restate-server");
Expand Down Expand Up @@ -87,9 +87,13 @@ pub(crate) enum ErrorInner {
IdentityVerification(#[from] VerifyError),
#[error("Cannot convert header '{0}', reason: {1}")]
Header(String, #[source] BoxError),
#[error("Cannot reply to discovery, got accept header '{0}' but currently supported discovery versions are v2 and v3")]
#[error(
"Cannot reply to discovery, got accept header '{0}' but currently supported discovery versions are v2 and v3"
)]
BadDiscoveryVersion(String),
#[error("The field '{0}' was set in the service/handler options, but it requires minimum discovery protocol version {1}")]
#[error(
"The field '{0}' was set in the service/handler options, but it requires minimum discovery protocol version {1}"
)]
FieldRequiresMinimumVersion(&'static str, u32),
#[error("Bad path '{0}', expected either '/discover' or '/invoke/service/handler'")]
BadPath(String),
Expand Down Expand Up @@ -224,7 +228,7 @@ impl Endpoint {
let (svc_name, handler_name) = match parts.get(parts.len() - 3..) {
None => return error_response(ErrorInner::BadPath(path.to_owned())),
Some(last_elements) if last_elements[0] != "invoke" => {
return error_response(ErrorInner::BadPath(path.to_owned()))
return error_response(ErrorInner::BadPath(path.to_owned()));
}
Some(last_elements) => (last_elements[1].to_owned(), last_elements[2].to_owned()),
};
Expand Down
4 changes: 2 additions & 2 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

use std::fmt::Debug;
use tracing::{
Event, Id, Metadata, Subscriber,
field::{Field, Visit},
span::{Attributes, Record},
Event, Id, Metadata, Subscriber,
};
use tracing_subscriber::{
Layer,
layer::{Context, Filter},
registry::LookupSpan,
Layer,
};

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http::{Request, Response};
use hyper::body::Incoming;
use hyper::service::Service;
use std::convert::Infallible;
use std::future::{ready, Ready};
use std::future::{Ready, ready};

/// Wraps [`Endpoint`] to implement hyper [`Service`].
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ use aws_lambda_events::encodings::Base64Data;
use bytes::Bytes;
use http::{HeaderMap, Method, Request, Uri};
use http_body_util::{BodyExt, Full};
use lambda_runtime::LambdaEvent;
use lambda_runtime::service_fn;
use lambda_runtime::tower::ServiceExt;
use lambda_runtime::LambdaEvent;
use serde::{Deserialize, Serialize};

use crate::endpoint::{Endpoint, HandleOptions, ProtocolMode};
Expand Down
Loading