Skip to content

How to add multiple errors if Messages functions take self ? #6

Answered by maxcountryman
HosMercury asked this question in Q&A
Discussion options

You must be logged in to vote

Each method returns self, so you can rebind the variable if you aren't able to use the fluent API directly. For instance, we can modify the example like so:

diff --git a/examples/basic.rs b/examples/basic.rs
index 19748d2..41df4ef 100644
--- a/examples/basic.rs
+++ b/examples/basic.rs
@@ -8,10 +8,10 @@ use axum::{
 use axum_messages::{Messages, MessagesManagerLayer};
 use tower_sessions::{MemoryStore, SessionManagerLayer};
 
-async fn set_messages_handler(messages: Messages) -> impl IntoResponse {
-    messages
-        .info("Hello, world!")
-        .debug("This is a debug message.");
+async fn set_messages_handler(mut messages: Messages) -> impl IntoResponse {
+    for message in ["foo…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@HosMercury
Comment options

@maxcountryman
Comment options

Answer selected by HosMercury
@HosMercury
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants