diff --git a/crates/automation/src/server.rs b/crates/automation/src/server.rs index 55cc32c1bb..939e866b0b 100644 --- a/crates/automation/src/server.rs +++ b/crates/automation/src/server.rs @@ -59,6 +59,7 @@ impl ServerLimits { /// How [`serve_with`] runs a server: its [`ServerLimits`], the clock its authentication deadline is /// read against, and a signal for each ended connection. A [`ServerLimits`] converts into the /// options with the real clock and no signal. +#[non_exhaustive] pub struct ServeOptions { /// The caps on lines and the time a connection has to authenticate. pub limits: ServerLimits, @@ -69,6 +70,18 @@ pub struct ServeOptions { pub ended: Option>, } +impl ServeOptions { + /// Sets the clock the authentication deadline is read against. + pub fn clock(self, clock: DeadlineClock) -> Self { + Self { clock, ..self } + } + + /// Sets the sender that gets `()` each time a connection has ended. + pub fn ended(self, ended: Sender<()>) -> Self { + Self { ended: Some(ended), ..self } + } +} + impl Default for ServeOptions { fn default() -> Self { ServerLimits::default().into() diff --git a/crates/automation/tests/it/control.rs b/crates/automation/tests/it/control.rs index 25e1a3a2e7..fb9dc04943 100644 --- a/crates/automation/tests/it/control.rs +++ b/crates/automation/tests/it/control.rs @@ -146,7 +146,7 @@ fn an_unauthenticated_connection_is_closed_at_the_deadline_whatever_it_sends() { let _ = read.send(()); now }); - let options = ServeOptions { limits: ServerLimits::default().auth_deadline(Duration::from_secs(10)), clock, ended: Some(ended) }; + let options = ServeOptions::from(ServerLimits::default().auth_deadline(Duration::from_secs(10))).clock(clock).ended(ended); let (rx, server) = server::serve_with(TcpListener::bind("127.0.0.1:0").expect("bound"), TOKEN.into(), host(), options).expect("started"); let mut stream = TcpStream::connect(server.addr).expect("connected"); stream.set_read_timeout(Some(HANG)).expect("timeout"); @@ -199,8 +199,7 @@ fn a_reset_connection_counts_as_closed() { fn serve_counting_ends() -> (Receiver, server::Listening, Receiver<()>) { let (ended, connection_ended) = channel(); let start = motion::now(); - let options = - ServeOptions { limits: ServerLimits::default().auth_deadline(Duration::from_secs(60)), clock: Arc::new(move || start), ended: Some(ended) }; + let options = ServeOptions::from(ServerLimits::default().auth_deadline(Duration::from_secs(60))).clock(Arc::new(move || start)).ended(ended); let (rx, server) = server::serve_with(TcpListener::bind("127.0.0.1:0").expect("bound"), TOKEN.into(), host(), options).expect("started"); (rx, server, connection_ended) } diff --git a/crates/ui-widgets/src/tile_grid/grid.rs b/crates/ui-widgets/src/tile_grid/grid.rs index 1b7549a19f..e753a3ad35 100644 --- a/crates/ui-widgets/src/tile_grid/grid.rs +++ b/crates/ui-widgets/src/tile_grid/grid.rs @@ -94,12 +94,21 @@ pub enum ColumnRule { /// Exactly this many columns share the width; zero asks for one. Exactly(usize), /// Centre the largest pictures that fit the view; fixed headers and tails that exceed it scroll normally. + /// [`ColumnRule::fit_to_view`] makes one. + #[non_exhaustive] FitToView { /// The most columns allowed. most_columns: usize, }, } +impl ColumnRule { + /// The rule that centres the largest pictures that fit the view, in at most `most_columns` columns. + pub const fn fit_to_view(most_columns: usize) -> Self { + ColumnRule::FitToView { most_columns } + } +} + /// What the grid reports besides the collection's events. #[derive(Clone, Debug, PartialEq)] #[non_exhaustive] diff --git a/crates/ui-widgets/tests/it/tile_grid/grid.rs b/crates/ui-widgets/tests/it/tile_grid/grid.rs index eff287b72f..bffe327a1c 100644 --- a/crates/ui-widgets/tests/it/tile_grid/grid.rs +++ b/crates/ui-widgets/tests/it/tile_grid/grid.rs @@ -365,7 +365,7 @@ fn fit_to_view_tiles_stay_in_view_and_fewer_tiles_are_larger() { .rows_stamp(1) .groups(&groups) .tail(&tails) - .column_rule(ColumnRule::FitToView { most_columns: most.get() }) + .column_rule(ColumnRule::fit_to_view(most.get())) .selection(Bind::bound(&mut *picks.borrow_mut())) .show_items(ui, &source, &mut |key, cx| { held.borrow_mut().tiles.insert(*key, cx.rect);