mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
Design lint: ServeOptions and ColumnRule::FitToView are non-exhaustive
ServeOptions gets clock and ended setters beside From<ServerLimits>; ColumnRule gets fit_to_view. The trials build them through those. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7abd484260
commit
7aa8f46dc6
4 files changed
+25
-4
No files matched your search
@@ -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<Sender<()>>,
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
@@ -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<ControlRequest>, 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)
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user