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

Use of clone in get_root #1

Open
NotThatRqd opened this issue Oct 28, 2023 · 1 comment
Open

Use of clone in get_root #1

NotThatRqd opened this issue Oct 28, 2023 · 1 comment

Comments

@NotThatRqd
Copy link
Owner

lib.rs

struct BtnifyState<S> {
    buttons_map: HashMap<String, Box<dyn (Fn(&S) -> ButtonResponse) + Send + Sync>>,
    user_state: S,
    page: Html<String>
}

/* ... */

async fn get_root<S: Send + Sync>(State(state): State<Arc<BtnifyState<S>>>) -> Html<String> {
    // TODO: DONT USE CLONE
    state.page.clone()
}

Clone is efficient.

@NotThatRqd
Copy link
Owner Author

Page can't be moved out of state and a reference to page is also difficult because state is an Arc. Perhaps using a different state method in Axum? https://docs.rs/axum/latest/axum/extract/struct.State.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant