Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp230632lqe; Wed, 27 Mar 2024 04:19:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfPYecnV3MPnXeR4yv7Um+yyWRDyqniCQzGcvzky3a2EHofO6X8mnLUxY3p6+qSsMzom2rkYndXRJQlPiuAv0j/YIWPeGeTGukgnt3wQ== X-Google-Smtp-Source: AGHT+IEsXfmTyJHVQ0B6XK5hG10B0XtFRpgrYAz3SNrIRz29rc2xiDRoKZGKsZNMurDhn/8zI73K X-Received: by 2002:a05:6808:10cc:b0:3c3:d201:1136 with SMTP id s12-20020a05680810cc00b003c3d2011136mr6051517ois.3.1711538376932; Wed, 27 Mar 2024 04:19:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711538376; cv=pass; d=google.com; s=arc-20160816; b=0P9b0bQ8B7VQUjVQokJI+6gtnGCIfo3sBX11qpmHZnMC/omb2BYzHlmIegDz3qfm0+ /XOiQNuP+tdT2IGX+mX0X1djuvUMV6MkGWI3qhEq4HmtzK90QHxtOUhDVi+m93vVk7GM ZRixSRx36vYW3qOgP+ZNQaau8fScgb1R1y3qiOGosVaJeEFR9HfsNf2Yc9FLmnxQrlDx 7i1Zy44JT9ULTOdhaX46VMwBTnW7FfbFC7i1Xz0G1fiQheNdPFXYCIZ7kDgEArw2wppA SuZx/tQnij09zCUUk77Sgo0vTzyHwi+b5DRxj9kI+ZRwMAKaeNbkClDbkNLWZRR+5Yfo cWjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=b+ixGN0r2/X/83UL4UB0Gt8jkXQcthsc8tHh8gZmqG0=; fh=MdyGqZw4hFaX4lU/qohExQLtxdvHfXJLSVw76VWLpJc=; b=Jo+RIlMxqLi/p47/SQiQ0u0cxBDEzoHU5NrtQNloTiQeNX8J0sxLCUEg6GmQieTBoI nS/bFOGXzqvLTqdlPxPhLoSFnBZpyxYLj9i2VWX7CYDTAWJfkcQR/Buyumk/wSsVfgxp Jsf8FJbE8EjoGmrCahADl13MzpmbK+ZyH2cDNfrJGxPZREpI7cEe+tTYTB+OcNQFCsN8 89OjAI99BUwyIO6AGoXMGndtd7R+ioXJ5pt7uLO38LgE+6Zti/ieWrOnjwLZGm78OYnG +Kez5E3g8ymwIfa3VjxV9VX+Mw2RCXtfaCEgieyaKQQ0KitLrSlWQ//7HkyFjhajeK3W XZOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=M0B4jITA; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-120739-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t1-20020a05622a01c100b0043120a116f8si9557055qtw.684.2024.03.27.04.19.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 04:19:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120739-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=M0B4jITA; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-120739-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120739-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6D2E21C28BB3 for ; Wed, 27 Mar 2024 11:19:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 039E25A792; Wed, 27 Mar 2024 11:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="M0B4jITA" Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (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 44D1959149 for ; Wed, 27 Mar 2024 11:18:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711538332; cv=none; b=NTcqLgGnanc/A9RYbqNe3AtUIp3ZfLAGQcf26YqJH/01I9UhnHDu09He9HbSWvmAh/lN9qNalCU8EjZMS7pesazTT5o9QhpNpxSO1EF0AorBk06UecTShyTLWz7aTn7bKYdO+5f8Fw8iDR1TVL1/4SGbVyVZk1Edvh/sEoTi/2E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711538332; 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=BEg0tOXoGqY6M/4FhWLfVqEjpTQElDGzJBFkl+NMiBvihGBE3rQ4GNjH15IcU28QSwti4mqMSSoaFJLxT+fTLMUgiapRfD187AnEEKDsxzwMfbPLqEJWdvP6QDyb92riGjviNUbmUMDonfYhmHFy2DvsXoJR3qdKZWXk1hsCGQo= 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=185.70.40.134 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 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: linux-kernel@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