Skip to main content

stern4rust/finding/model/
public_entry_point.rs

1// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5// One publicly reachable function, identified by name and arity.
6//
7// Arity rather than the parameter types, and that limit is the rule's whole
8// honesty: at a call site `check(3, &paths)` gives two arguments and nothing
9// more. Whether `3` is a `usize` and `&paths` a `&[&str]` is type inference,
10// which is rustc's work and not something a syntax tree can answer. Arity is
11// available, costs nothing, and separates `new()` from `new(a, b)` -- which is
12// most of what a name alone confuses.
13//
14// The receiver does not count. `printer.with_fixed(12)` passes one argument and
15// `pub fn with_fixed(self, fixed: usize)` declares one parameter besides self,
16// so the two match.
17#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
18pub struct PublicEntryPoint {
19    pub name: String,
20    pub arity: usize,
21}
22
23impl PublicEntryPoint {
24    pub fn new(name: &str, arity: usize) -> Self {
25        Self {
26            name: name.to_string(),
27            arity,
28        }
29    }
30
31    // How the offence names it, so two entry points sharing a name are still
32    // told apart on the page.
33    pub fn signature(&self) -> String {
34        format!("{}/{}", self.name, self.arity)
35    }
36}