Skip to content

Commit

Permalink
Use nightly for Rustfmt (#2630)
Browse files Browse the repository at this point in the history
* add rustfmt.toml, use nightly in CI, update contributing docs

* run `cargo +nightly fmt`
  • Loading branch information
ranile authored Apr 21, 2022
1 parent 12c9ebb commit c28a71e
Show file tree
Hide file tree
Showing 175 changed files with 928 additions and 758 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
profile: minimal
components: rustfmt
Expand All @@ -25,4 +25,5 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: fmt
toolchain: nightly
args: --all -- --check
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The following command checks the code using Rustfmt and Clippy:
cargo make lint
```

To automatically fix formatting issues, run `cargo fmt` first.
To automatically fix formatting issues, run `cargo +nightly fmt` first.

## Benchmarks

Expand Down Expand Up @@ -107,4 +107,4 @@ Below, you can find some useful guidance and best practices on how to write APIs
The source code of our website ([https://yew.rs](https://yew.rs)) is in the [website directory](website).
Most of the times, edits can be done in markdown.

[website/README.md](website/README.md) has more detailed instructions.
[website/README.md](website/README.md) has more detailed instructions.
1 change: 1 addition & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ run_task = { name = ["lint", "lint-release", "tests"], fork = true }
[tasks.lint]
category = "Checks"
description = "Check formatting and run Clippy"
toolchain = "nightly"
run_task = { name = ["lint-flow"], fork = true }

[tasks.tests]
Expand Down
1 change: 1 addition & 0 deletions examples/agents/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod native_worker;

use std::rc::Rc;

use yew::{html, Component, Context, Html};
use yew_agent::{Bridge, Bridged};

Expand Down
4 changes: 2 additions & 2 deletions examples/agents/src/native_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub struct Worker {
}

impl yew_agent::Worker for Worker {
type Reach = Public<Self>;
type Message = Msg;
type Input = Request;
type Message = Msg;
type Output = Response;
type Reach = Public<Self>;

fn create(link: WorkerLink<Self>) -> Self {
let duration = 3;
Expand Down
8 changes: 5 additions & 3 deletions examples/boids/src/boid.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::iter;

use rand::Rng;
use yew::{html, Html};

use crate::math::{self, Mean, Vector2D, WeightedMean};
use crate::settings::Settings;
use crate::simulation::SIZE;
use rand::Rng;
use std::iter;
use yew::{html, Html};

#[derive(Clone, Debug, PartialEq)]
pub struct Boid {
Expand Down
7 changes: 4 additions & 3 deletions examples/boids/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ impl App {
fn view_settings(&self, link: &Scope<Self>) -> Html {
let Self { settings, .. } = self;

// This helper macro creates a callback which applies the new value to the current settings and sends `Msg::ChangeSettings`.
// Thanks to this, we don't need to have "ChangeBoids", "ChangeCohesion", etc. messages,
// but it comes at the cost of cloning the `Settings` struct each time.
// This helper macro creates a callback which applies the new value to the current settings
// and sends `Msg::ChangeSettings`. Thanks to this, we don't need to have
// "ChangeBoids", "ChangeCohesion", etc. messages, but it comes at the cost of
// cloning the `Settings` struct each time.
macro_rules! settings_callback {
($link:expr, $settings:ident; $key:ident as $ty:ty) => {{
let settings = $settings.clone();
Expand Down
5 changes: 3 additions & 2 deletions examples/boids/src/simulation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use gloo::timers::callback::Interval;
use yew::{html, Component, Context, Html, Properties};

use crate::boid::Boid;
use crate::math::Vector2D;
use crate::settings::Settings;
use gloo::timers::callback::Interval;
use yew::{html, Component, Context, Html, Properties};

pub const SIZE: Vector2D = Vector2D::new(1600.0, 1000.0);

Expand Down
4 changes: 3 additions & 1 deletion examples/boids/src/slider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::cell::Cell;

use web_sys::HtmlInputElement;
use yew::{events::InputEvent, html, Callback, Component, Context, Html, Properties, TargetCast};
use yew::events::InputEvent;
use yew::{html, Callback, Component, Context, Html, Properties, TargetCast};

thread_local! {
static SLIDER_ID: Cell<usize> = Cell::default();
Expand Down
3 changes: 1 addition & 2 deletions examples/contexts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ mod producer;
mod struct_component_subscriber;
mod subscriber;

use msg_ctx::MessageProvider;
use producer::Producer;
use struct_component_subscriber::StructComponentSubscriber;
use subscriber::Subscriber;
use yew::prelude::*;

use msg_ctx::MessageProvider;

#[function_component]
pub fn App() -> Html {
html! {
Expand Down
4 changes: 2 additions & 2 deletions examples/contexts/src/struct_component_subscriber.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::msg_ctx::MessageContext;

use yew::prelude::*;

use super::msg_ctx::MessageContext;

pub enum Msg {
MessageContextUpdated(MessageContext),
}
Expand Down
4 changes: 2 additions & 2 deletions examples/contexts/src/subscriber.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::msg_ctx::MessageContext;

use yew::prelude::*;

use super::msg_ctx::MessageContext;

#[function_component]
pub fn Subscriber() -> Html {
let msg_ctx = use_context::<MessageContext>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/dyn_create_destroy_apps/src/counter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use gloo::{console, timers::callback::Interval};
use gloo::console;
use gloo::timers::callback::Interval;
use yew::prelude::*;

pub struct CounterModel {
Expand All @@ -17,7 +18,6 @@ pub enum CounterMessage {

impl Component for CounterModel {
type Message = CounterMessage;

type Properties = CounterProps;

fn create(ctx: &Context<Self>) -> Self {
Expand Down
3 changes: 2 additions & 1 deletion examples/dyn_create_destroy_apps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub enum Msg {
}

pub struct App {
apps: Slab<(Element, AppHandle<CounterModel>)>, // Contains the spawned apps and their parent div elements
apps: Slab<(Element, AppHandle<CounterModel>)>, /* Contains the spawned apps and their
* parent div elements */
apps_container_ref: NodeRef,
}

Expand Down
6 changes: 3 additions & 3 deletions examples/file_upload/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::HashMap;

use web_sys::{Event, HtmlInputElement};
use yew::{html, html::TargetCast, Component, Context, Html};

use gloo_file::callbacks::FileReader;
use gloo_file::File;
use web_sys::{Event, HtmlInputElement};
use yew::html::TargetCast;
use yew::{html, Component, Context, Html};

type Chunks = bool;

Expand Down
11 changes: 6 additions & 5 deletions examples/function_memory_game/src/components/app.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::cell::RefCell;
use std::rc::Rc;

use gloo::timers::callback::{Interval, Timeout};
use std::{cell::RefCell, rc::Rc};
use yew::prelude::*;
use yew::{function_component, html};

use crate::components::{
chessboard::Chessboard, game_status_board::GameStatusBoard, score_board::ScoreBoard,
};

use crate::components::chessboard::Chessboard;
use crate::components::game_status_board::GameStatusBoard;
use crate::components::score_board::ScoreBoard;
use crate::constant::Status;
use crate::state::{Action, State};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::constant::Status;
use yew::prelude::*;
use yew::{function_component, html, Properties};

use crate::constant::Status;

#[derive(Properties, Clone, PartialEq)]
pub struct Props {
pub status: Status,
Expand Down
6 changes: 3 additions & 3 deletions examples/function_memory_game/src/components/score_board.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use yew::{function_component, html, Html, Properties};

use crate::components::{
score_board_best_score::BestScore, score_board_logo::Logo, score_board_progress::GameProgress,
};
use crate::components::score_board_best_score::BestScore;
use crate::components::score_board_logo::Logo;
use crate::components::score_board_progress::GameProgress;

#[derive(PartialEq, Properties, Clone)]
pub struct Props {
Expand Down
3 changes: 2 additions & 1 deletion examples/function_memory_game/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::rc::Rc;

use gloo::storage::{LocalStorage, Storage};
use serde::{Deserialize, Serialize};
use std::rc::Rc;
use yew::prelude::*;

use crate::constant::{CardName, Status, KEY_BEST_SCORE};
Expand Down
10 changes: 6 additions & 4 deletions examples/function_router/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use yew_router::history::{AnyHistory, History, MemoryHistory};
use yew_router::prelude::*;

use crate::components::nav::Nav;
use crate::pages::{
author::Author, author_list::AuthorList, home::Home, page_not_found::PageNotFound, post::Post,
post_list::PostList,
};
use crate::pages::author::Author;
use crate::pages::author_list::AuthorList;
use crate::pages::home::Home;
use crate::pages::page_not_found::PageNotFound;
use crate::pages::post::Post;
use crate::pages::post_list::PostList;

#[derive(Routable, PartialEq, Clone, Debug)]
pub enum Route {
Expand Down
5 changes: 4 additions & 1 deletion examples/function_router/src/components/author_card.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::rc::Rc;

use crate::{content::Author, generator::Generated, Route};
use yew::prelude::*;
use yew_router::prelude::*;

use crate::content::Author;
use crate::generator::Generated;
use crate::Route;

#[derive(Clone, Debug, PartialEq, Properties)]
pub struct Props {
pub seed: u32,
Expand Down
4 changes: 2 additions & 2 deletions examples/function_router/src/components/pagination.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;
use serde::Serialize;
use std::ops::Range;

use serde::{Deserialize, Serialize};
use yew::prelude::*;
use yew_router::prelude::*;

Expand Down
5 changes: 4 additions & 1 deletion examples/function_router/src/components/post_card.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::rc::Rc;

use crate::{content::PostMeta, generator::Generated, Route};
use yew::prelude::*;
use yew_router::components::Link;

use crate::content::PostMeta;
use crate::generator::Generated;
use crate::Route;

#[derive(Clone, Debug, PartialEq, Properties)]
pub struct Props {
pub seed: u32,
Expand Down
5 changes: 4 additions & 1 deletion examples/function_router/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use lazy_static::lazy_static;
use lipsum::MarkovChain;
use rand::{distributions::Bernoulli, rngs::StdRng, seq::IteratorRandom, Rng, SeedableRng};
use rand::distributions::Bernoulli;
use rand::rngs::StdRng;
use rand::seq::IteratorRandom;
use rand::{Rng, SeedableRng};

const KEYWORDS: &str = include_str!("../data/keywords.txt");
const SYLLABLES: &str = include_str!("../data/syllables.txt");
Expand Down
6 changes: 4 additions & 2 deletions examples/function_router/src/pages/author.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::components::author_card::AuthorState;
use crate::{content, generator::Generated};
use yew::prelude::*;

use crate::components::author_card::AuthorState;
use crate::content;
use crate::generator::Generated;

#[derive(Clone, Debug, Eq, PartialEq, Properties)]
pub struct Props {
pub seed: u32,
Expand Down
4 changes: 3 additions & 1 deletion examples/function_router/src/pages/author_list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::components::{author_card::AuthorCard, progress_delay::ProgressDelay};
use rand::{distributions, Rng};
use yew::prelude::*;

use crate::components::author_card::AuthorCard;
use crate::components::progress_delay::ProgressDelay;

/// Amount of milliseconds to wait before showing the next set of authors.
const CAROUSEL_DELAY_MS: u32 = 15000;

Expand Down
4 changes: 3 additions & 1 deletion examples/function_router/src/pages/post.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::rc::Rc;

use crate::{content, generator::Generated, Route};
use content::PostPart;
use yew::prelude::*;
use yew_router::prelude::*;

use crate::generator::Generated;
use crate::{content, Route};

#[derive(Clone, Debug, Eq, PartialEq, Properties)]
pub struct Props {
pub seed: u32,
Expand Down
7 changes: 4 additions & 3 deletions examples/function_router/src/pages/post_list.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::components::pagination::PageQuery;
use crate::components::{pagination::Pagination, post_card::PostCard};
use crate::Route;
use yew::prelude::*;
use yew_router::prelude::*;

use crate::components::pagination::{PageQuery, Pagination};
use crate::components::post_card::PostCard;
use crate::Route;

const ITEMS_PER_PAGE: u32 = 10;
const TOTAL_PAGES: u32 = u32::MAX / ITEMS_PER_PAGE;

Expand Down
5 changes: 3 additions & 2 deletions examples/function_todomvc/src/components/entry.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::hooks::use_bool_toggle::use_bool_toggle;
use crate::state::Entry as Item;
use web_sys::{HtmlInputElement, MouseEvent};
use yew::events::{Event, FocusEvent, KeyboardEvent};
use yew::prelude::*;

use crate::hooks::use_bool_toggle::use_bool_toggle;
use crate::state::Entry as Item;

#[derive(PartialEq, Properties, Clone)]
pub struct EntryProps {
pub entry: Item,
Expand Down
3 changes: 2 additions & 1 deletion examples/function_todomvc/src/components/filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::state::Filter as FilterEnum;
use yew::prelude::*;

use crate::state::Filter as FilterEnum;

#[derive(PartialEq, Properties)]
pub struct FilterProps {
pub filter: FilterEnum,
Expand Down
1 change: 1 addition & 0 deletions examples/function_todomvc/src/hooks/use_bool_toggle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::Deref;
use std::rc::Rc;

use yew::prelude::*;

#[derive(Clone)]
Expand Down
8 changes: 4 additions & 4 deletions examples/function_todomvc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ mod components;
mod hooks;
mod state;

use components::{
entry::Entry as EntryItem, filter::Filter as FilterItem, header_input::HeaderInput,
info_footer::InfoFooter,
};
use components::entry::Entry as EntryItem;
use components::filter::Filter as FilterItem;
use components::header_input::HeaderInput;
use components::info_footer::InfoFooter;

const KEY: &str = "yew.functiontodomvc.self";

Expand Down
Loading

1 comment on commit c28a71e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: c28a71e Previous: 12c9ebb Ratio
yew-struct-keyed 01_run1k 161.692 409.5715 0.39
yew-struct-keyed 02_replace1k 178.0285 459.9345 0.39
yew-struct-keyed 03_update10th1k_x16 266.93600000000004 331.492 0.81
yew-struct-keyed 04_select1k 45.5195 54.391000000000005 0.84
yew-struct-keyed 05_swap1k 68.72649999999999 81.303 0.85
yew-struct-keyed 06_remove-one-1k 24.7005 27.429 0.90
yew-struct-keyed 07_create10k 2767.9415 2873.4399999999996 0.96
yew-struct-keyed 08_create1k-after1k_x2 375.348 404.256 0.93
yew-struct-keyed 09_clear1k_x8 165.3475 148.47 1.11
yew-struct-keyed 21_ready-memory 1.457233428955078 1.457233428955078 1
yew-struct-keyed 22_run-memory 1.6922874450683594 1.6660003662109375 1.02
yew-struct-keyed 23_update5-memory 1.6698074340820312 1.6955299377441406 0.98
yew-struct-keyed 24_run5-memory 1.9438438415527344 1.709758758544922 1.14
yew-struct-keyed 25_run-clear-memory 1.3277015686035156 1.3279914855957031 1.00
yew-struct-keyed 31_startup-ci 1730.172 1731.948 1.00
yew-struct-keyed 32_startup-bt 28.116 29.708 0.95
yew-struct-keyed 33_startup-mainthreadcost 183.8880000000001 214.4240000000001 0.86
yew-struct-keyed 34_startup-totalbytes 328.7392578125 328.7392578125 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.