Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extensions, refactor context and request-related #47

Merged
merged 21 commits into from
Dec 25, 2024

Conversation

Desiders
Copy link
Owner

@Desiders Desiders commented Dec 25, 2024

Code example:

// instead of `context.insert("url", Box::new(url.into_boxed_str()));`
context.insert("url", url.into_boxed_str());
// instead of `context.get("url").unwrap().downcast_ref::<Box<str>>();`
context.get::<Box<str>>("url");
  • Refactor path and usage of Request in middlewares and filters.

    Now all data like context and extractors will be passed in request for filters and middlewares instead of pass them in different arguments:

New filter:

fn lowercase_filter(request: &mut Request) -> impl Future<Output = bool> {
    let result = request
        .update
        .text()
        .map_or(false, |text| text.to_lowercase() == text);

    async move { result }
}

Old filter:

fn lowercase_filter(_bot: &Bot, update: &Update, _context: &Context) -> impl Future<Output = bool>
{
    let result = update
        .text()
        .map_or(false, |text| text.to_lowercase() == text);

    async move { result }
}

As you can see, there also added &mut, so you can without any problems change the request (there no Arc now)

  • Rename FromEventAndContext to Extractor and HandlerObject to HandlerComposition
  • Docs small fixes
  • Update MSRV to 1.71.1
  • Change path of telers::{router/...}::Request to telers::Request

@Desiders Desiders self-assigned this Dec 25, 2024
@Desiders Desiders added A-telers Area: telers A-telers-macros Area: telers-macros breaking change A PR that makes a breaking change. P-high High priority labels Dec 25, 2024
@Desiders Desiders merged commit 491566a into dev-1.x Dec 25, 2024
3 checks passed
@Desiders Desiders deleted the add-extensions branch December 25, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-telers Area: telers A-telers-macros Area: telers-macros breaking change A PR that makes a breaking change. P-high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant