Improve rustdoc in Rust OSS

PiperOrigin-RevId: 695705103
pull/19218/head
Protobuf Team Bot 3 months ago committed by Copybara-Service
parent 5140c02cf7
commit f78a589481
  1. 17
      csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs
  2. 29
      rust/protobuf.rs
  3. 44
      rust/shared.rs
  4. 24
      rust/test/shared/BUILD
  5. 11
      rust/test/shared/no_internal_access_test.rs

@ -1,17 +0,0 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#endregion
namespace Google.Protobuf.Reflection;
internal sealed partial class FeatureSetDescriptor
{
// Canonical serialized form of the edition defaults, generated by embed_edition_defaults.
private const string DefaultsBase64 =
"ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH";
}

@ -7,12 +7,13 @@
//! Rust Protobuf Runtime
//!
//! This file forwards to `shared.rs`, which exports a kernel-specific
//! `__runtime`. Rust Protobuf gencode actually depends directly on kernel
//! specific crates. This crate exists for two reasons:
//! - To be able to use `protobuf` as a crate name for both cpp and upb kernels
//! from user code.
//! - To make it more difficult to access internal-only items by default.
//! This file exists as the public entry point for the Rust Protobuf runtime. It
//! is a thin re-export of the `shared.rs` file but is needed for two reasons:
//! - To create a single `protobuf` crate name for either cpp and upb kernels
//! from user code (toggled at compile time).
//! - Blocks the __internal and __runtime modules from being re-exported to
//! application code, unless they use one of our visibility-restricted targets
//! (gencode does have access to them).
#[cfg(cpp_kernel)]
use protobuf_cpp as kernel;
@ -20,6 +21,18 @@ use protobuf_cpp as kernel;
#[cfg(upb_kernel)]
use protobuf_upb as kernel;
pub use kernel::__public::*;
/// Block these two mods from being re-exported by the `pub use`
/// below (glob use automatically only adds things that aren't otherwise
/// defined).
///
/// By creating a const instead of an empty mod it is easier to have a test
/// that confirms this targeted 'blocking' is working as intended.
#[doc(hidden)]
#[allow(non_upper_case_globals)]
pub const __internal: () = ();
pub use kernel::prelude;
#[doc(hidden)]
#[allow(non_upper_case_globals)]
pub const __runtime: () = ();
pub use kernel::*;

@ -18,33 +18,23 @@ use std::fmt;
// This problem is referred to as "perfect derive".
// https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/
/// Everything in `__public` is re-exported in `protobuf.rs`.
/// These are the items protobuf users can access directly.
#[doc(hidden)]
pub mod __public {
pub use crate::codegen_traits::{
create::Parse,
interop::{MessageMutInterop, MessageViewInterop, OwnedMessageInterop},
read::Serialize,
write::{Clear, ClearAndParse, MergeFrom},
Message, MessageMut, MessageView,
};
pub use crate::cord::{ProtoBytesCow, ProtoStringCow};
pub use crate::r#enum::{Enum, UnknownEnumValue};
pub use crate::map::{Map, MapIter, MapMut, MapView, ProxiedInMapValue};
pub use crate::optional::Optional;
pub use crate::proto;
pub use crate::proxied::{
AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy,
View, ViewProxy,
};
pub use crate::repeated::{
ProxiedInRepeated, Repeated, RepeatedIter, RepeatedMut, RepeatedView,
};
pub use crate::string::{ProtoBytes, ProtoStr, ProtoString, Utf8Error};
pub use crate::{ParseError, SerializeError};
}
pub use __public::*;
pub use crate::codegen_traits::{
create::Parse,
interop::{MessageMutInterop, MessageViewInterop, OwnedMessageInterop},
read::Serialize,
write::{Clear, ClearAndParse, MergeFrom},
Message, MessageMut, MessageView,
};
pub use crate::cord::{ProtoBytesCow, ProtoStringCow};
pub use crate::map::{Map, MapIter, MapMut, MapView, ProxiedInMapValue};
pub use crate::optional::Optional;
pub use crate::proxied::{
AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View,
ViewProxy,
};
pub use crate::r#enum::{Enum, UnknownEnumValue};
pub use crate::repeated::{ProxiedInRepeated, Repeated, RepeatedIter, RepeatedMut, RepeatedView};
pub use crate::string::{ProtoBytes, ProtoStr, ProtoString, Utf8Error};
pub mod prelude;

@ -517,3 +517,27 @@ rust_test(
"@crate_index//:googletest",
],
)
rust_test(
name = "no_internal_access_test_cpp",
srcs = ["no_internal_access_test.rs"],
aliases = {
"//rust:protobuf_cpp_export": "protobuf",
},
deps = [
"//rust:protobuf_cpp_export",
"@crate_index//:googletest",
],
)
rust_test(
name = "no_internal_access_test_upb",
srcs = ["no_internal_access_test.rs"],
aliases = {
"//rust:protobuf_upb_export": "protobuf",
},
deps = [
"//rust:protobuf_upb_export",
"@crate_index//:googletest",
],
)

@ -0,0 +1,11 @@
use googletest::gtest;
use protobuf::{__internal, __runtime};
#[gtest]
#[allow(clippy::unit_cmp)]
fn test_no_internal_access() {
// This test is to ensure that the `__internal` and `__runtime` mods are
// 'blocked' by instead being a unit type instead of a module.
assert_eq!(__internal, ());
assert_eq!(__runtime, ());
}
Loading…
Cancel
Save