// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Buffers;
using System.Diagnostics.Contracts;
using System.IO;
using System.Runtime.CompilerServices;
using MemoryStream = CommunityToolkit.HighPerformance.Streams.MemoryStream;
namespace CommunityToolkit.HighPerformance;
///
/// Helpers for working with the type.
///
public static class IMemoryOwnerExtensions
{
///
/// Returns a wrapping the contents of the given of instance.
///
/// The input of instance.
/// A wrapping the data within .
///
/// The caller does not need to track the lifetime of the input of
/// instance, as the returned will take care of disposing that buffer when it is closed.
///
/// Thrown when has an invalid data store.
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Stream AsStream(this IMemoryOwner memoryOwner)
{
return MemoryStream.Create(memoryOwner);
}
}