From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 840965D498 for ; Wed, 27 Mar 2024 11:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=188.165.51.139 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711538339; cv=none; b=oH+j07cPmdmvjz0Ec9Em+Q5/UdWG5qvhBeZBEyiQqIqTaUliwZWz8pe8IQMjStj9uvYpYswRIZwwMSVq4F+ZQUum8XlLBnUlOrmwVPVB6DM9Ne//FA5U6ggyaqvOunIxhcZtlcNTjS6x0if+yJZQ9NBqnldMTqm6DFf31ec6eys= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711538339; c=relaxed/simple; bh=mhOieoq7DfxAaJ++d+O0WtR+BfTTgESKgZZHlPaztWg=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G0ygWO4z+lQ3ncKVlNe8YbA+EX63bbkWth/PxsQa8AveISS60wJSo8VUPC4xuo48rtgikyHfZoYT74oQN0QLOIfBdWDGvuCsAvvdg6nAcKLltHEy4zsmQnc6GgqmusRDOGUkH9+iHOUgc+6JLWoiSVu8FoOmroXSdu+kU69XmTM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=M0B4jITA; arc=none smtp.client-ip=188.165.51.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="M0B4jITA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1711538321; x=1711797521; bh=b+ixGN0r2/X/83UL4UB0Gt8jkXQcthsc8tHh8gZmqG0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=M0B4jITA+ZBAu+TvTskwA5UPn3mlMurWkFylBxDnHhZW19+fG7cTiwLFINyYSE0oI ZoJ+8kBSbJtbSzvusod86Bd15kt1ix50aAt4SvbxONrXhCKEBjItFc/mrtVySGNDoM LOkRqViBBLNI0Bn3wTDFPuVfM7Kl8hfy25QC+WLhoWIYGA/4eoa61S/07heIgRdQp5 oQt6/xQVjjjZwV2q2oJUgAiCqKJbR4vrkLw39rhrW2hAJVYF0UcXViDiz0a0Ds1A74 NWEK77SjvvL1UcyQK9yICxHKVgM6VpTg7R8Z7WEH3rLabzNPtNTfAmlWITYQvQOLT4 2y6qfHdiG4qug== Date: Wed, 27 Mar 2024 11:18:28 +0000 To: Boqun Feng From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , John Stultz , Stephen Boyd , Valentin Obst Subject: Re: [PATCH 2/5] rust: time: Introduce Duration type Message-ID: In-Reply-To: References: <20240324223339.971934-1-boqun.feng@gmail.com> <20240324223339.971934-3-boqun.feng@gmail.com> <4hYJbftgOk1JOPbJ6CfKZell6ngp8GljwIUIB1vOQvIf-7jiogG5xDtCvcMlF7cIJAdy9fO5HLQh_8ohnWNB3MAaj0xjAGeyyDowemgunOU=@proton.me> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 26.03.24 18:17, Boqun Feng wrote: > On Tue, Mar 26, 2024 at 10:11:07AM -0700, Boqun Feng wrote: > [...] >>>> +impl Duration { >>>> + /// Creates a new duration of `ns` nanoseconds. >>>> + pub const fn new(ns: i64) -> Self { >>>> + Self { inner: ns } >>>> + } >>>> + >>>> + /// Divides the number of nanoseconds by a compile-time constant. >>>> + #[inline] >>>> + fn divns_constant(self) -> i64 { >>>> + self.to_ns() / DIV >>>> + } >>> >>> I am a bit confused, why is this better than writing >>> `self.to_ns() / DIV` at the callsite? >>> >> >> Hmm.. you're right, there should be no difference I think. If there is >> nothing I'm missing from Alice, I will drop this function in the next >> version. >> >=20 > On a second thought, I think this prevents accidentally divide a > non-const value, in other words, if you use this function, you're > guaranteed the divisor is a constant, and you have the compiler checking > that for you. So in that sense, I think it makes sense to remain it > here. Thoughts? I don't see the value in that. It does not prevent me from just doing `self.to_ns() / DIV` now. I imagine that 99% of the time users will want to get milliseconds or microseconds and we should have methods for that (when we have users). But for the last 1% I don't think we need this method. --=20 Cheers, Benno