Move __runtime into __internal::runtime

Clarify the rustdoc on __internal

PiperOrigin-RevId: 703541883
pull/19548/head
Protobuf Team Bot 3 months ago committed by Copybara-Service
parent f10826ed25
commit b025398f9c
  1. 13
      rust/internal.rs
  2. 14
      rust/map.rs
  3. 10
      rust/protobuf.rs
  4. 14
      rust/repeated.rs
  5. 32
      rust/shared.rs
  6. 2
      rust/string.rs
  7. 6
      rust/test/cpp/interop/main.rs
  8. 7
      rust/test/shared/no_internal_access_test.rs
  9. 2
      src/google/protobuf/compiler/rust/generator.cc

@ -19,10 +19,17 @@ pub use crate::ProtoStr;
use crate::Proxied;
pub use std::fmt::Debug;
#[cfg(all(bzl, cpp_kernel))]
#[path = "cpp.rs"]
pub mod runtime;
#[cfg(any(not(bzl), upb_kernel))]
#[path = "upb.rs"]
pub mod runtime;
// TODO: Temporarily re-export these symbols which are now under
// __runtime under __internal since some external callers using it through
// __internal.
pub use crate::__runtime::{PtrAndLen, RawMap, RawMessage, RawRepeatedField};
// runtime under __internal directly since some external callers using it
// through __internal.
pub use runtime::{PtrAndLen, RawMap, RawMessage, RawRepeatedField};
/// Used to protect internal-only items from being used accidentally.
#[derive(Debug)]

@ -8,8 +8,8 @@
use crate::{
AsMut, AsView, IntoMut, IntoProxied, IntoView, MutProxied, MutProxy, Proxied, Proxy, View,
ViewProxy,
__internal::runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter},
__internal::{Private, SealedInternal},
__runtime::{InnerMap, InnerMapMut, RawMap, RawMapIter},
};
use std::marker::PhantomData;
@ -104,7 +104,11 @@ where
}
impl<K: Proxied, V: ProxiedInMapValue<K>> Proxied for Map<K, V> {
type View<'msg> = MapView<'msg, K, V> where K: 'msg, V: 'msg;
type View<'msg>
= MapView<'msg, K, V>
where
K: 'msg,
V: 'msg;
}
impl<K: Proxied, V: ProxiedInMapValue<K>> AsView for Map<K, V> {
@ -116,7 +120,11 @@ impl<K: Proxied, V: ProxiedInMapValue<K>> AsView for Map<K, V> {
}
impl<K: Proxied, V: ProxiedInMapValue<K>> MutProxied for Map<K, V> {
type Mut<'msg> = MapMut<'msg, K, V> where K: 'msg, V: 'msg;
type Mut<'msg>
= MapMut<'msg, K, V>
where
K: 'msg,
V: 'msg;
}
impl<K: Proxied, V: ProxiedInMapValue<K>> AsMut for Map<K, V> {

@ -11,9 +11,9 @@
//! 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).
//! - Blocks the __internal module 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;
@ -31,8 +31,4 @@ use protobuf_upb as kernel;
#[allow(non_upper_case_globals)]
pub const __internal: () = ();
#[doc(hidden)]
#[allow(non_upper_case_globals)]
pub const __runtime: () = ();
pub use kernel::*;

@ -5,6 +5,7 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
use std::fmt::{self, Debug};
use std::iter;
use std::iter::FusedIterator;
/// Repeated scalar fields are implemented around the runtime-specific
@ -12,13 +13,12 @@ use std::iter::FusedIterator;
/// runtime-specific representation of a repeated scalar (`upb_Array*` on upb,
/// and `RepeatedField<T>*` on cpp).
use std::marker::PhantomData;
use std::fmt::{self, Debug};
use crate::{
AsMut, AsView, IntoMut, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Proxied, Proxy, View,
ViewProxy,
__internal::runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField},
__internal::{Private, SealedInternal},
__runtime::{InnerRepeated, InnerRepeatedMut, RawRepeatedField},
};
/// Views the elements in a `repeated` field of `T`.
@ -379,7 +379,10 @@ impl<T> Proxied for Repeated<T>
where
T: ProxiedInRepeated,
{
type View<'msg> = RepeatedView<'msg, T> where Repeated<T>: 'msg;
type View<'msg>
= RepeatedView<'msg, T>
where
Repeated<T>: 'msg;
}
impl<T> SealedInternal for Repeated<T> where T: ProxiedInRepeated {}
@ -399,7 +402,10 @@ impl<T> MutProxied for Repeated<T>
where
T: ProxiedInRepeated,
{
type Mut<'msg> = RepeatedMut<'msg, T> where Repeated<T>: 'msg;
type Mut<'msg>
= RepeatedMut<'msg, T>
where
Repeated<T>: 'msg;
}
impl<T> AsMut for Repeated<T>

@ -5,10 +5,6 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
//! Kernel-agnostic logic for the Rust Protobuf Runtime.
//!
//! For kernel-specific logic this crate delegates to the respective `__runtime`
//! crate.
#![deny(unsafe_op_in_unsafe_fn)]
use std::fmt;
@ -38,22 +34,24 @@ pub use crate::string::{ProtoBytes, ProtoStr, ProtoString, Utf8Error};
pub mod prelude;
/// Everything in `__internal` is allowed to change without it being considered
/// a breaking change for the protobuf library. Nothing in here should be
/// exported in `protobuf.rs`.
/// The `__internal` module is for necessary encapsulation breaks between
/// generated code and the runtime.
///
/// These symbols are never intended to be used by application code under any
/// circumstances.
///
/// In blaze/bazel builds, this symbol is actively hidden from application
/// code by having a shim crate in front that does not re-export this symbol,
/// and a different BUILD visibility-restricted target that is used by the
/// generated code.
///
/// In Cargo builds we have no good way to technically hide this
/// symbol while still allowing it from codegen, so it is only by private by
/// convention. As application code should never use this module, anything
/// changes under `__internal` is not considered a semver breaking change.
#[path = "internal.rs"]
pub mod __internal;
/// Everything in `__runtime` is allowed to change without it being considered
/// a breaking change for the protobuf library. Nothing in here should be
/// exported in `protobuf.rs`.
#[cfg(all(bzl, cpp_kernel))]
#[path = "cpp.rs"]
pub mod __runtime;
#[cfg(any(not(bzl), upb_kernel))]
#[path = "upb.rs"]
pub mod __runtime;
mod codegen_traits;
mod cord;
#[path = "enum.rs"]

@ -9,8 +9,8 @@
#![allow(dead_code)]
#![allow(unused)]
use crate::__internal::runtime::{InnerProtoString, PtrAndLen, RawMessage};
use crate::__internal::{Private, SealedInternal};
use crate::__runtime::{InnerProtoString, PtrAndLen, RawMessage};
use crate::{
utf8::Utf8Chunks, AsView, IntoProxied, IntoView, Mut, MutProxied, MutProxy, Optional, Proxied,
Proxy, View, ViewProxy,

@ -8,7 +8,7 @@
use googletest::prelude::*;
use protobuf_cpp::prelude::*;
use protobuf_cpp::__runtime::PtrAndLen;
use protobuf_cpp::__internal::runtime::PtrAndLen;
use protobuf_cpp::{MessageMutInterop, MessageViewInterop, OwnedMessageInterop};
use std::ffi::c_void;
@ -31,7 +31,9 @@ extern "C" {
fn TakeOwnershipAndGetOptionalInt64(msg: *mut c_void) -> i64;
fn DeserializeInteropTestMessage(data: *const u8, len: usize) -> *mut c_void;
fn MutateInteropTestMessage(msg: *mut c_void);
fn SerializeInteropTestMessage(msg: *const c_void) -> protobuf_cpp::__runtime::SerializedData;
fn SerializeInteropTestMessage(
msg: *const c_void,
) -> protobuf_cpp::__internal::runtime::SerializedData;
fn DeleteInteropTestMessage(msg: *mut c_void);
fn NewWithExtension() -> *mut c_void;

@ -1,11 +1,10 @@
use protobuf::{__internal, __runtime};
use protobuf::__internal;
#[googletest::test]
#[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.
// This test is to ensure that the `__internal` is 'blocked' by instead being a
// unit type instead of a module.
assert_eq!(__internal, ());
assert_eq!(__runtime, ());
}

@ -150,7 +150,7 @@ bool RustGenerator::Generate(const FileDescriptor* file,
{"std", "::std"},
{"pb", "::protobuf"},
{"pbi", "::protobuf::__internal"},
{"pbr", "::protobuf::__runtime"},
{"pbr", "::protobuf::__internal::runtime"},
{"NonNull", "::std::ptr::NonNull"},
{"Phantom", "::std::marker::PhantomData"},
{"Result", "::std::result::Result"},

Loading…
Cancel
Save