Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3502827lqp; Tue, 26 Mar 2024 10:47:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX4cDdY6jxvZKAe23ld+oJYbotRC31uudjKRK4gY0zzYtIUcH+O5DR3QFflVegD6SFSIwAGidaiHhZJsLkKplv1J17fRL0eC6MyQh0u6w== X-Google-Smtp-Source: AGHT+IFqovglSSQT24oyMGmOBBDttoygjOlytEp8zq0KLnpzhX+ZLZsB/dGkG5iJ6lazU5VWcvj+ X-Received: by 2002:a05:6a21:32a9:b0:1a3:6f54:fdf6 with SMTP id yt41-20020a056a2132a900b001a36f54fdf6mr2060715pzb.10.1711475264358; Tue, 26 Mar 2024 10:47:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711475264; cv=pass; d=google.com; s=arc-20160816; b=ZtzECxUnGQbAoKpbMdbWHOZGRoh3ic3OHEqo8SKyHzyjx42FCBDB3c/QijhZ/QmtxE DBVmbFCVhsXfgFMaSNkiA32HQg4BUcbX+4OEQbQeNOCehz4fTBTRQmD44oEy/QFbqAfG 0O8SQZTnYxLJIarH60TIs+nkuumQIaP6NKGK+1oG79iOWTIAnzo5PgY8kkLhWWcwjK3Y 4OeX1Scmsi/cNHSQORjz94bCDPlb0QPbB3MJuypGMqtJPhm8VWWnaJTFjxzlO8hE5V/4 dsWVGPSiH32nn2v3kkP+lpr3Tbm69DSXVTvsm8fK0owxHs/DYCdKdU4+wAlOELrdf0Nj HZAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=7T5hEhkUDazJ47kggL6Q/TiVuUfZy8/rH8kDSRQfdQM=; fh=7xX2NR0lo9L8tg5e1UXCWyTduZZreQB4pcr8mSQ0qV8=; b=W+UVyKehFKyebTvXhBYIjTafKNEids6mueMgmyx82zwiNSNf+oYf6//xn6zYbWQyv3 lw2Wwm3NnXW2mt7RoVC2fL1aAWryWDV3tAn5qDD5afvS0AiL1waaWd6/ACrph1K3YBsh 5kvqRYfPH48+EYkSG8pWaML8dS7khoOnAnxDi8VOu5iczuGDj37x0Mw217CzCnCSoavP bWQzXHeW+s+ZddIweEcegdIWGtCD0DmHoulhqvk573XpIXg/8aMJ7ddYXIlQIYf4nB+x ZQHjSR1GngIWSxpSQTtgTvcOrz3uqTJ3q674a3cSQORSsc2i8zBh69vZfLDrmA4nlPwh GCHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BhtthlM9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-119577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119577-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id c192-20020a6335c9000000b005dcc0363c32si9961869pga.596.2024.03.26.10.47.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:47:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BhtthlM9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-119577-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119577-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 676ECB265C4 for ; Tue, 26 Mar 2024 17:22:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6E701CFA8; Tue, 26 Mar 2024 17:22:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BhtthlM9" Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BA671C6B0; Tue, 26 Mar 2024 17:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711473721; cv=none; b=pZWhtrWJS6mNechfSM7/672boc9CAdKClMxU61Z6DiqFDFwZwQ3DmiZRER8RqHl2slzZ+ANusPtjZ+T3XdkJa3ZWOXkO25v+UmBKeuy1ZCRnFf4o3QGcrCuXUyTm8ywwb1tPaABQN2vpGtklb/bwAo9jTLpWQg45BwzYirepzd0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711473721; c=relaxed/simple; bh=jZd3DMYTrkPjgcF+GXb0XDthojSFtmH0ibUcyxTWHgU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=snF8vsuxekFQR7TjUodmvzzJMWrhiNYJVzJI+SW6NUEktP5g8cn8Fjiyl+cdZDxe9i41H9EFzSE3MtAx8F1pr3V1Ic94xb2LvgYUZ70IyoaSkPW1sitzThJLdWlSbFt4qQHWH3LRPpVc3rZ4IMl78uGmjuVrVkn34VhEhZu0z3g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BhtthlM9; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-789db917876so351186285a.1; Tue, 26 Mar 2024 10:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711473719; x=1712078519; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=7T5hEhkUDazJ47kggL6Q/TiVuUfZy8/rH8kDSRQfdQM=; b=BhtthlM9bFY0vBOiLrF4eyxTrmb8l8V0AnhjaCENBIkCfmjQ1lxZvhkc8yaZXPauHA JhIzfG48RqvECKlNPG94CXXU8BAi0IqhGTlWd8n9LlrW6f+cDmX4jq4f4z+WTy5tJ8DW TYkBlfKMGdkvDLTFr2Eq/coBguHA+Ojez0VJuthMz8IgU1RuJgMdQtETQD0amaA4+Hd0 jhXFLLh/ymKCUGLKc7vsawOLLAzQ/E4lGWl6UOx3rccqN48aNfag2t3anSm6FZed2A9o ZFigZ+Im+/BrG20iO8Ug47vgj770XEFRs+cUEFzsL4m8zF8y/hJ9R5jzg2WtkSgJPmwp Qo3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711473719; x=1712078519; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7T5hEhkUDazJ47kggL6Q/TiVuUfZy8/rH8kDSRQfdQM=; b=U5avNB5vmvQLsccnF6ZJ+F6dR5nT8cbj/a6MKlNo7mO7FUu1/oYIBWXK6/pXEWbP8s cc6DUYkAnwWcMM9aUXofe7xCysI1brSxD2e2DpRZ6GZH7IH+W9Aut+55OB46aRZHxeuf MBVRFp2+9iMu5OXWOpw9kAMWEkIIaD1SjcN62ABpv6R0omeKu2NL6rVIsIsBUeF/A3GG 7U8iR8yyzXVwMAsXtQbUlqSoVHuZ8n6RfBZYFGuWhy3ZBQrpSQgiwJHisXpl05P8HUNo tAX5x7fhMNTG6K9yGsI6lMOrkXsXOH+pyaefedpc9E5VeCMvGssbTnnynzJChhEl00cs Nchw== X-Forwarded-Encrypted: i=1; AJvYcCX+KpG1HlkdsYPmGeJit/5WsM+e9Jnq1OFC2xxtsLE/XEYp4e4Zy0UUuZ/cYs6Eu1CGQsvnpxOlMhlcKDZikj6fIzWgfhItdgUxQdwr X-Gm-Message-State: AOJu0YzFeq4J/bu3vbp6OX5vP1mLzl+SFZdC5kRd2xweuOh410BbFQsG L0vpDBScOYIxj2VCd62QhRt8Mpw0dXT9h43/AKKh9cnJ5prP2aRc X-Received: by 2002:ae9:f714:0:b0:78a:2900:418e with SMTP id s20-20020ae9f714000000b0078a2900418emr1875997qkg.60.1711473718776; Tue, 26 Mar 2024 10:21:58 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id z22-20020ae9c116000000b0078a68410731sm415879qki.25.2024.03.26.10.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:21:58 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfauth.nyi.internal (Postfix) with ESMTP id 82FE71200074; Tue, 26 Mar 2024 13:17:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 26 Mar 2024 13:17:47 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddufedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Mar 2024 13:17:46 -0400 (EDT) Date: Tue, 26 Mar 2024 10:17:13 -0700 From: Boqun Feng To: 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 , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , John Stultz , Stephen Boyd , Valentin Obst Subject: Re: [PATCH 2/5] rust: time: Introduce Duration type Message-ID: References: <20240324223339.971934-1-boqun.feng@gmail.com> <20240324223339.971934-3-boqun.feng@gmail.com> <4hYJbftgOk1JOPbJ6CfKZell6ngp8GljwIUIB1vOQvIf-7jiogG5xDtCvcMlF7cIJAdy9fO5HLQh_8ohnWNB3MAaj0xjAGeyyDowemgunOU=@proton.me> 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=us-ascii Content-Disposition: inline In-Reply-To: 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. > 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? Regards, Boqun > Regards, > Boqun > > > -- > > Cheers, > > Benno > > > > > + > > > + /// Returns the number of milliseconds. > > > + #[inline] > > > + pub fn to_ms(self) -> i64 { > > > + self.divns_constant::() > > > + } > > > + > > > + /// Returns the number of nanoseconds. > > > + #[inline] > > > + pub fn to_ns(self) -> i64 { > > > + self.inner > > > + } > > > +} > > > -- > > > 2.44.0 > > >